Search is not available for this dataset
text string | meta dict |
|---|---|
/*
Copyright 2010-2011, D. E. Shaw Research.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of D. E. Shaw Research nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <gsl/gsl_randist.h>
#include <stdio.h>
#include "random123/philox.h"
#include "random123/threefry.h"
#include "random123/gsl_microrng.h"
/* Compute pi, using the gsl_ran_flat distribution with
an underlying threefry4x64 counter-based rng (cbrng).
We can call cbrng 8 times between calls to cbrng_reset */
GSL_MICRORNG(cbrng, threefry4x64); /* creates gsl_rng_cbrng */
#include "pi_check.h"
int main(int argc, char **argv){
unsigned long hits = 0, tries = 0;
gsl_rng *r;
(void)argc; (void)argv; /* unused */
threefry4x64_ctr_t c = {{0}};
threefry4x64_key_t k = {{0}};
r = gsl_rng_alloc(gsl_rng_cbrng);
printf("%lu uniforms from %s\n", NTRIES, gsl_rng_name(r));
while (tries < NTRIES) {
double x, y;
c.v[0]++; /* increment the counter */
cbrng_reset(r, c, k); /* reset the rng to the new counter */
x = gsl_ran_flat (r, -1.0, 1.0);
y = gsl_ran_flat (r, -1.0, 1.0);
if( x*x + y*y < 1.0 )
hits++;
tries++;
}
gsl_rng_free (r);
return pi_check(hits, tries);
}
| {
"alphanum_fraction": 0.7182721713,
"avg_line_length": 38.4705882353,
"ext": "c",
"hexsha": "68478a8edd219c22d8513bbe5910e8d1d1359ef3",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "kabicm/arbor",
"max_forks_repo_path": "random123/examples/pi_gsl.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "kabicm/arbor",
"max_issues_repo_path": "random123/examples/pi_gsl.c",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cfab5fd6a2e6a211c097659c96dcc098ee806e68",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "kabicm/arbor",
"max_stars_repo_path": "random123/examples/pi_gsl.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 654,
"size": 2616
} |
/**
*
* @file qwrapper_zlanhe.c
*
* PLASMA core_blas quark wrapper
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Julien Langou
* @author Henricus Bouwmeester
* @author Mathieu Faverge
* @date 2010-11-15
* @precisions normal z -> c
*
**/
#include <lapacke.h>
#include "common.h"
/***************************************************************************//**
*
**/
void QUARK_CORE_zlanhe(Quark *quark, Quark_Task_Flags *task_flags,
int norm, PLASMA_enum uplo, int N,
const PLASMA_Complex64_t *A, int LDA, int szeA,
int szeW, double *result)
{
szeW = max(1, szeW);
DAG_CORE_LANHE;
QUARK_Insert_Task(quark, CORE_zlanhe_quark, task_flags,
sizeof(PLASMA_enum), &norm, VALUE,
sizeof(PLASMA_enum), &uplo, VALUE,
sizeof(int), &N, VALUE,
sizeof(PLASMA_Complex64_t)*szeA, A, INPUT,
sizeof(int), &LDA, VALUE,
sizeof(double)*szeW, NULL, SCRATCH,
sizeof(double), result, OUTPUT,
0);
}
/***************************************************************************//**
*
**/
void QUARK_CORE_zlanhe_f1(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum norm, PLASMA_enum uplo, int N,
const PLASMA_Complex64_t *A, int LDA, int szeA,
int szeW, double *result,
double *fake, int szeF)
{
szeW = max(1, szeW);
DAG_CORE_LANHE;
if ( result == fake ) {
QUARK_Insert_Task(quark, CORE_zlanhe_quark, task_flags,
sizeof(PLASMA_enum), &norm, VALUE,
sizeof(PLASMA_enum), &uplo, VALUE,
sizeof(int), &N, VALUE,
sizeof(PLASMA_Complex64_t)*szeA, A, INPUT,
sizeof(int), &LDA, VALUE,
sizeof(double)*szeW, NULL, SCRATCH,
sizeof(double)*szeF, result, OUTPUT | GATHERV,
0);
} else {
QUARK_Insert_Task(quark, CORE_zlanhe_f1_quark, task_flags,
sizeof(PLASMA_enum), &norm, VALUE,
sizeof(PLASMA_enum), &uplo, VALUE,
sizeof(int), &N, VALUE,
sizeof(PLASMA_Complex64_t)*szeA, A, INPUT,
sizeof(int), &LDA, VALUE,
sizeof(double)*szeW, NULL, SCRATCH,
sizeof(double), result, OUTPUT,
sizeof(double)*szeF, fake, OUTPUT | GATHERV,
0);
}
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_zlanhe_quark = PCORE_zlanhe_quark
#define CORE_zlanhe_quark PCORE_zlanhe_quark
#endif
void CORE_zlanhe_quark(Quark *quark)
{
double *normA;
int norm;
PLASMA_enum uplo;
int N;
PLASMA_Complex64_t *A;
int LDA;
double *work;
quark_unpack_args_7(quark, norm, uplo, N, A, LDA, work, normA);
*normA = LAPACKE_zlanhe_work(
LAPACK_COL_MAJOR,
lapack_const(norm), lapack_const(uplo),
N, A, LDA, work);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_zlanhe_f1_quark = PCORE_zlanhe_f1_quark
#define CORE_zlanhe_f1_quark PCORE_zlanhe_f1_quark
#endif
void CORE_zlanhe_f1_quark(Quark *quark)
{
double *normA;
int norm;
PLASMA_enum uplo;
int N;
PLASMA_Complex64_t *A;
int LDA;
double *work;
double *fake;
quark_unpack_args_8(quark, norm, uplo, N, A, LDA, work, normA, fake);
*normA = LAPACKE_zlanhe_work(
LAPACK_COL_MAJOR,
lapack_const(norm), lapack_const(uplo),
N, A, LDA, work);
}
| {
"alphanum_fraction": 0.4925195915,
"avg_line_length": 33.4206349206,
"ext": "c",
"hexsha": "8d35182b4ef75af2a3d3f69f1792e97e2e5c5bea",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zhuangsc/Plasma-ompss1",
"max_forks_repo_path": "core_blas-qwrapper/qwrapper_zlanhe.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zhuangsc/Plasma-ompss1",
"max_issues_repo_path": "core_blas-qwrapper/qwrapper_zlanhe.c",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zhuangsc/Plasma-ompss1",
"max_stars_repo_path": "core_blas-qwrapper/qwrapper_zlanhe.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1107,
"size": 4211
} |
#pragma once
#include "Common.h"
#include <stdexcept>
#include <gsl/gsl>
namespace winlogo::utils {
/**
* This exception is raised when failing to run VirtualProtect.
*/
class VirtualProtectFailedError : public std::runtime_error {
public:
VirtualProtectFailedError() noexcept;
};
/**
* This is a RAII class for temporarily changing the protection of a memory region.
*/
class MemoryProtectionGuard {
public:
MemoryProtectionGuard(void* startAddress, size_t size, DWORD protection);
NO_COPY(MemoryProtectionGuard);
NO_MOVE(MemoryProtectionGuard);
~MemoryProtectionGuard() noexcept;
private:
/// The start address of the memory region for which the protection should be changed.
void* m_startAddress;
/// The size of the memory region for which the protection should be changed.
size_t m_size;
/// The old protection to be restored in the end.
DWORD m_oldProtection;
/**
* Run VirtualProtect for the stored address and store the previous protection in
* m_oldProtection.
*/
bool doVirtualProtect(DWORD protection) noexcept;
};
} // namespace winlogo::utils
| {
"alphanum_fraction": 0.72823219,
"avg_line_length": 25.2666666667,
"ext": "h",
"hexsha": "39e6ee47a698c2e60514f03f4ffdaabfe23bd9b3",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-20T12:06:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-20T12:06:02.000Z",
"max_forks_repo_head_hexsha": "9ad51469e3ed4bb593303d4d7919c484a3be092e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shsh999/WinLogo",
"max_forks_repo_path": "winlogo_core/MemoryProtectionGuard.h",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "9ad51469e3ed4bb593303d4d7919c484a3be092e",
"max_issues_repo_issues_event_max_datetime": "2021-12-29T12:13:05.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-12-23T01:01:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shsh999/WinLogo",
"max_issues_repo_path": "winlogo_core/MemoryProtectionGuard.h",
"max_line_length": 90,
"max_stars_count": 12,
"max_stars_repo_head_hexsha": "9ad51469e3ed4bb593303d4d7919c484a3be092e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shsh999/WinLogo",
"max_stars_repo_path": "winlogo_core/MemoryProtectionGuard.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T07:18:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-04T22:10:13.000Z",
"num_tokens": 240,
"size": 1137
} |
/* fft/dft_complex.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
*
* 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 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
* 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.
*/
#include <config.h>
#include <math.h>
#include <gsl/gsl_complex.h>
#include <gsl/gsl_dft_complex.h>
#include <gsl/gsl_errno.h>
#include "complex_internal.h"
int
gsl_dft_complex_forward (const double data[],
const size_t stride, const size_t n,
double result[])
{
gsl_fft_direction sign = forward;
int status = gsl_dft_complex (data, stride, n, result, sign);
return status;
}
int
gsl_dft_complex_backward (const double data[],
const size_t stride, const size_t n,
double result[])
{
gsl_fft_direction sign = backward;
int status = gsl_dft_complex (data, stride, n, result, sign);
return status;
}
int
gsl_dft_complex_inverse (const double data[],
const size_t stride, const size_t n,
double result[])
{
gsl_fft_direction sign = backward;
int status = gsl_dft_complex (data, stride, n, result, sign);
/* normalize inverse fft with 1/n */
{
const ATOMIC norm = 1.0 / n;
size_t i;
for (i = 0; i < n; i++)
{
REAL(result,stride,i) *= norm;
IMAG(result,stride,i) *= norm;
}
}
return status;
}
int
gsl_dft_complex (const double data[],
const size_t stride, const size_t n,
double result[],
const gsl_fft_direction sign)
{
size_t i, j, exponent;
const double d_theta = 2.0 * ((int) sign) * M_PI / (double) n;
/* FIXME: check that input length == output length and give error */
for (i = 0; i < n; i++)
{
ATOMIC sum_real = 0;
ATOMIC sum_imag = 0;
exponent = 0;
for (j = 0; j < n; j++)
{
double theta = d_theta * (double) exponent;
/* sum = exp(i theta) * data[j] */
ATOMIC w_real = cos (theta);
ATOMIC w_imag = sin (theta);
ATOMIC data_real = REAL(data,stride,j);
ATOMIC data_imag = IMAG(data,stride,j);
sum_real += w_real * data_real - w_imag * data_imag;
sum_imag += w_real * data_imag + w_imag * data_real;
exponent = (exponent + i) % n;
}
REAL(result,stride,i) = sum_real;
IMAG(result,stride,i) = sum_imag;
}
return 0;
}
| {
"alphanum_fraction": 0.6104443724,
"avg_line_length": 27.0438596491,
"ext": "c",
"hexsha": "dcecf3e18d5f8696671b457e23c3ad09d4d69ce8",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z",
"max_forks_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zzpwahaha/Chimera-Control-Trim",
"max_forks_repo_path": "Chimera/3rd_Party/GSL_MSVC/fft/dft_complex.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "zzpwahaha/Chimera-Control-Trim",
"max_issues_repo_path": "Chimera/3rd_Party/GSL_MSVC/fft/dft_complex.c",
"max_line_length": 81,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df1bbf6bea0b87b8c7c9a99dce213fdc249118f2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zzpwahaha/Chimera-Control-Trim",
"max_stars_repo_path": "Chimera/3rd_Party/GSL_MSVC/fft/dft_complex.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z",
"num_tokens": 798,
"size": 3083
} |
#pragma once
#include <gsl/gsl>
struct ScanWordResult;
struct GlyphVertex2d;
struct TigFont;
struct TigTextStyle;
struct TigRect;
struct TigFontMetrics;
using namespace gsl;
namespace gfx {
class RenderingDevice;
class ShapeRenderer2d;
class TextEngine;
}
class FontRenderer {
public:
explicit FontRenderer(gfx::RenderingDevice& g);
~FontRenderer();
void RenderRun(cstring_span<> text,
int x,
int y,
const TigRect& bounds,
TigTextStyle& style,
const TigFont& font);
private:
void RenderGlyphs(const GlyphVertex2d* vertices2d, int textureId, int glyphCount);
static void Rotate2d(float& x, float& y,
float rotCos, float rotSin,
float centerX, float centerY);
struct Impl;
std::unique_ptr<Impl> mImpl;
};
/*
Separates a block of text given flags into words split up
on lines and renders them.
*/
class TextLayouter {
friend class FontRenderer;
public:
TextLayouter(gfx::RenderingDevice& device, gfx::ShapeRenderer2d& shapeRenderer);
~TextLayouter();
void LayoutAndDraw(gsl::cstring_span<> text, const TigFont &font, TigRect& extents, TigTextStyle& style);
void Measure(const TigFont &font, const TigTextStyle &style, TigFontMetrics &metrics);
private:
void DrawBackgroundOrOutline(const TigRect& rect, const TigTextStyle& style);
static int GetGlyphIdx(char ch, const char *text);
ScanWordResult ScanWord(const char* text,
int firstIdx,
int textLength,
int tabWidth,
bool lastLine,
const TigFont& font,
const TigTextStyle& style,
int remainingSpace);
std::pair<int, int> TextLayouter::MeasureCharRun(cstring_span<> text,
const TigTextStyle& style,
const TigRect& extents,
int extentsWidth,
const TigFont& font,
int linePadding,
bool lastLine);
bool HasMoreText(cstring_span<> text, int tabWidth);
void LayoutAndDrawVanilla(gsl::cstring_span<> text,
const TigFont &font,
TigRect& extents,
TigTextStyle& style);
void MeasureVanilla(const TigFont &font,
const TigTextStyle &style,
TigFontMetrics &metrics) const;
uint32_t MeasureVanillaLine(const TigFont &font, const TigTextStyle &style, const char *text) const;
uint32_t MeasureVanillaParagraph(const TigFont &font, const TigTextStyle &style, const char *text) const;
uint32_t CountLinesVanilla(uint32_t maxWidth, uint32_t maxLines, const char *text, const TigFont &font, const TigTextStyle &style) const;
static const char *sEllipsis;
gfx::TextEngine &mTextEngine;
FontRenderer mRenderer;
std::unique_ptr<class FontsMapping> mMapping;
gfx::ShapeRenderer2d& mShapeRenderer;
};
| {
"alphanum_fraction": 0.7669172932,
"avg_line_length": 26.0515463918,
"ext": "h",
"hexsha": "39b4cb5993f8268e9e67b41347b8875ba850d909",
"lang": "C",
"max_forks_count": 25,
"max_forks_repo_forks_event_max_datetime": "2021-11-15T23:14:51.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-04T21:19:53.000Z",
"max_forks_repo_head_hexsha": "f0e552289822fea908f16daa379fa568b1bd286d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "edoipi/TemplePlus",
"max_forks_repo_path": "TemplePlus/fonts/fonts.h",
"max_issues_count": 457,
"max_issues_repo_head_hexsha": "f0e552289822fea908f16daa379fa568b1bd286d",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T02:19:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-01T22:07:45.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "edoipi/TemplePlus",
"max_issues_repo_path": "TemplePlus/fonts/fonts.h",
"max_line_length": 138,
"max_stars_count": 69,
"max_stars_repo_head_hexsha": "f0e552289822fea908f16daa379fa568b1bd286d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "edoipi/TemplePlus",
"max_stars_repo_path": "TemplePlus/fonts/fonts.h",
"max_stars_repo_stars_event_max_datetime": "2022-02-15T06:13:04.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-05T14:09:25.000Z",
"num_tokens": 652,
"size": 2527
} |
#include "linearwaves.h"
#include <gsl/gsl_integration.h>
typedef struct GSL_params {
double x;
int m;
} GSL_params;
void init_params(void) {
params.mp = 1e-5;
params.softening = .6*.05;
params.softening2 = params.softening*params.softening;
params.a = 1;
params.indirect = TRUE;
return;
}
double potential(double phi, double x) {
double res = -pow(x*x + params.a*params.a + params.softening2 - 2*params.a*x*cos(phi),-.5);
if (params.indirect) {
res += cos(phi)*params.a/(x*x);
}
return res;
}
double dr_potential(double phi, double x) {
double res = ( x - params.a*cos(phi)) * pow(x*x + params.a*params.a + params.softening2 - 2*params.a*x*cos(phi),-1.5);
if (params.indirect) {
res -= 2* cos(phi)*params.a/(x*x*x);
}
return res;
}
double dp_potential(double phi, double x) {
double res = params.a*x*sin(phi)* pow(x*x + params.a*params.a + params.softening2 - 2*params.a*x*cos(phi),-1.5);
if (params.indirect) {
res += sin(phi)*params.a/(x*x);
}
return res;
}
double pfunc(double phi, void *params) {
GSL_params p = *(GSL_params *)params;
double x = p.x;
int m = p.m;
return cos(m*phi) * potential(phi,x);
}
double dpfunc(double phi, void *params) {
GSL_params p = *(GSL_params *)params;
double x = p.x;
int m = p.m;
return cos(m*phi) * dr_potential(phi,x);
}
void force(double x, int m, double complex *res) {
int nspace = 1000;
int gsl_order = 5;
gsl_integration_workspace *w = gsl_integration_workspace_alloc(nspace);
gsl_function F1, F2;
F1.function = &pfunc;
F2.function = &dpfunc;
GSL_params p;
p.x = x;
p.m = m;
F1.params = &p;
F2.params = &p;
double tol = params.tol;
double error;
double res_r, dr_res_r;
gsl_integration_qag(&F1,0,M_PI, tol, tol, nspace, gsl_order , w, &res_r, &error);
gsl_integration_qag(&F2,0,M_PI, tol, tol, nspace, gsl_order , w, &dr_res_r, &error);
res_r *= params.mp/M_PI;
dr_res_r *= params.mp/M_PI;
res[0] = dr_res_r;// *-1;
res[1] = res_r ;//* -I * m/x;
res[2] = 0;
gsl_integration_workspace_free(w);
return;
}
| {
"alphanum_fraction": 0.6050839764,
"avg_line_length": 25.0340909091,
"ext": "c",
"hexsha": "cd9e4caad627acdccd05fe1050851600772d9e5f",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6551cb210311962d734dcaae292534fc27ce1490",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "adamdempsey90/linearwaves",
"max_forks_repo_path": "src/planet.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6551cb210311962d734dcaae292534fc27ce1490",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "adamdempsey90/linearwaves",
"max_issues_repo_path": "src/planet.c",
"max_line_length": 122,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6551cb210311962d734dcaae292534fc27ce1490",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "adamdempsey90/linearwaves",
"max_stars_repo_path": "src/planet.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 687,
"size": 2203
} |
static char help[] =
"Solves time-dependent heat equation in 2D using TS. Option prefix -ht_.\n"
"Equation is u_t = D_0 laplacian u + f. Domain is (0,1) x (0,1).\n"
"Boundary conditions are non-homogeneous Neumann in x and periodic in y.\n"
"Energy is conserved (for these particular conditions/source) and an extra\n"
"'monitor' is demonstrated. Discretization is by centered finite differences.\n"
"Converts the PDE into a system X_t = G(t,X) (PETSc type 'nonlinear') by\n"
"method of lines. Uses backward Euler time-stepping by default.\n";
#include <petsc.h>
typedef struct {
double D0; // conductivity
} HeatCtx;
static double f_source(double x, double y) {
return 3.0 * exp(-25.0 * (x-0.6) * (x-0.6)) * sin(2.0*PETSC_PI*y);
}
static double gamma_neumann(double y) {
return sin(6.0 * PETSC_PI * y);
}
extern PetscErrorCode Spacings(DMDALocalInfo*, double*, double*);
extern PetscErrorCode EnergyMonitor(TS, int, double, Vec, void*);
extern PetscErrorCode FormRHSFunctionLocal(DMDALocalInfo*, double, double**,
double**, HeatCtx*);
extern PetscErrorCode FormRHSJacobianLocal(DMDALocalInfo*, double, double**,
Mat, Mat, HeatCtx*);
int main(int argc,char **argv)
{
PetscErrorCode ierr;
HeatCtx user;
TS ts;
Vec u;
DM da;
DMDALocalInfo info;
double t0, tf;
PetscBool monitorenergy = PETSC_FALSE;
PetscInitialize(&argc,&argv,(char*)0,help);
user.D0 = 1.0;
ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "ht_", "options for heat", ""); CHKERRQ(ierr);
ierr = PetscOptionsReal("-D0","constant thermal diffusivity",
"heat.c",user.D0,&user.D0,NULL);CHKERRQ(ierr);
ierr = PetscOptionsBool("-monitor","also display total heat energy at each step",
"heat.c",monitorenergy,&monitorenergy,NULL);CHKERRQ(ierr);
ierr = PetscOptionsEnd(); CHKERRQ(ierr);
//STARTDMDASETUP
ierr = DMDACreate2d(PETSC_COMM_WORLD,
DM_BOUNDARY_NONE, DM_BOUNDARY_PERIODIC, DMDA_STENCIL_STAR,
5,4,PETSC_DECIDE,PETSC_DECIDE, // default to hx=hx=0.25 grid
1,1, // degrees of freedom, stencil width
NULL,NULL,&da); CHKERRQ(ierr);
ierr = DMSetFromOptions(da); CHKERRQ(ierr);
ierr = DMSetUp(da); CHKERRQ(ierr);
ierr = DMCreateGlobalVector(da,&u); CHKERRQ(ierr);
//ENDDMDASETUP
//STARTTSSETUP
ierr = TSCreate(PETSC_COMM_WORLD,&ts); CHKERRQ(ierr);
ierr = TSSetProblemType(ts,TS_NONLINEAR); CHKERRQ(ierr);
ierr = TSSetDM(ts,da); CHKERRQ(ierr);
ierr = TSSetApplicationContext(ts,&user); CHKERRQ(ierr);
ierr = DMDATSSetRHSFunctionLocal(da,INSERT_VALUES,
(DMDATSRHSFunctionLocal)FormRHSFunctionLocal,&user); CHKERRQ(ierr);
ierr = DMDATSSetRHSJacobianLocal(da,
(DMDATSRHSJacobianLocal)FormRHSJacobianLocal,&user); CHKERRQ(ierr);
if (monitorenergy) {
ierr = TSMonitorSet(ts,EnergyMonitor,&user,NULL); CHKERRQ(ierr);
}
ierr = TSSetType(ts,TSBDF); CHKERRQ(ierr);
ierr = TSSetTime(ts,0.0); CHKERRQ(ierr);
ierr = TSSetMaxTime(ts,0.1); CHKERRQ(ierr);
ierr = TSSetTimeStep(ts,0.001); CHKERRQ(ierr);
ierr = TSSetExactFinalTime(ts,TS_EXACTFINALTIME_MATCHSTEP); CHKERRQ(ierr);
ierr = TSSetFromOptions(ts);CHKERRQ(ierr);
//ENDTSSETUP
// report on set up
ierr = TSGetTime(ts,&t0); CHKERRQ(ierr);
ierr = TSGetMaxTime(ts,&tf); CHKERRQ(ierr);
ierr = DMDAGetLocalInfo(da,&info); CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD,
"solving on %d x %d grid for t0=%g to tf=%g ...\n",
info.mx,info.my,t0,tf); CHKERRQ(ierr);
// solve
ierr = VecSet(u,0.0); CHKERRQ(ierr); // initial condition
ierr = TSSolve(ts,u); CHKERRQ(ierr);
VecDestroy(&u); TSDestroy(&ts); DMDestroy(&da);
return PetscFinalize();
}
PetscErrorCode Spacings(DMDALocalInfo *info, double *hx, double *hy) {
if (hx) *hx = 1.0 / (double)(info->mx-1);
if (hy) *hy = 1.0 / (double)(info->my); // periodic direction
return 0;
}
//STARTMONITOR
PetscErrorCode EnergyMonitor(TS ts, int step, double time, Vec u,
void *ctx) {
PetscErrorCode ierr;
HeatCtx *user = (HeatCtx*)ctx;
double lenergy = 0.0, energy, dt, hx, hy, **au;
int i,j;
MPI_Comm com;
DM da;
DMDALocalInfo info;
ierr = TSGetDM(ts,&da); CHKERRQ(ierr);
ierr = DMDAGetLocalInfo(da,&info); CHKERRQ(ierr);
ierr = DMDAVecGetArrayRead(da,u,&au); CHKERRQ(ierr);
for (j = info.ys; j < info.ys + info.ym; j++) {
for (i = info.xs; i < info.xs + info.xm; i++) {
if ((i == 0) || (i == info.mx-1))
lenergy += 0.5 * au[j][i];
else
lenergy += au[j][i];
}
}
ierr = DMDAVecRestoreArrayRead(da,u,&au); CHKERRQ(ierr);
ierr = Spacings(&info,&hx,&hy); CHKERRQ(ierr);
lenergy *= hx * hy;
ierr = PetscObjectGetComm((PetscObject)(da),&com); CHKERRQ(ierr);
ierr = MPI_Allreduce(&lenergy,&energy,1,MPI_DOUBLE,MPI_SUM,com); CHKERRQ(ierr);
ierr = TSGetTimeStep(ts,&dt); CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD," energy = %9.2e nu = %8.4f\n",
energy,user->D0*dt/(hx*hy)); CHKERRQ(ierr);
return 0;
}
//ENDMONITOR
//STARTRHSFUNCTION
PetscErrorCode FormRHSFunctionLocal(DMDALocalInfo *info,
double t, double **au,
double **aG, HeatCtx *user) {
PetscErrorCode ierr;
int i, j, mx = info->mx;
double hx, hy, x, y, ul, ur, uxx, uyy;
ierr = Spacings(info,&hx,&hy); CHKERRQ(ierr);
for (j = info->ys; j < info->ys + info->ym; j++) {
y = hy * j;
for (i = info->xs; i < info->xs + info->xm; i++) {
x = hx * i;
// apply Neumann b.c.s
ul = (i == 0) ? au[j][i+1] + 2.0 * hx * gamma_neumann(y)
: au[j][i-1];
ur = (i == mx-1) ? au[j][i-1] : au[j][i+1];
uxx = (ul - 2.0 * au[j][i]+ ur) / (hx*hx);
// DMDA is periodic in y
uyy = (au[j-1][i] - 2.0 * au[j][i]+ au[j+1][i]) / (hy*hy);
aG[j][i] = user->D0 * (uxx + uyy) + f_source(x,y);
}
}
return 0;
}
//ENDRHSFUNCTION
//STARTRHSJACOBIAN
PetscErrorCode FormRHSJacobianLocal(DMDALocalInfo *info,
double t, double **au,
Mat J, Mat P, HeatCtx *user) {
PetscErrorCode ierr;
int i, j, ncols;
const double D = user->D0;
double hx, hy, hx2, hy2, v[5];
MatStencil col[5],row;
ierr = Spacings(info,&hx,&hy); CHKERRQ(ierr);
hx2 = hx * hx; hy2 = hy * hy;
for (j = info->ys; j < info->ys+info->ym; j++) {
row.j = j; col[0].j = j;
for (i = info->xs; i < info->xs+info->xm; i++) {
// set up a standard 5-point stencil for the row
row.i = i;
col[0].i = i;
v[0] = - 2.0 * D * (1.0 / hx2 + 1.0 / hy2);
col[1].j = j-1; col[1].i = i; v[1] = D / hy2;
col[2].j = j+1; col[2].i = i; v[2] = D / hy2;
col[3].j = j; col[3].i = i-1; v[3] = D / hx2;
col[4].j = j; col[4].i = i+1; v[4] = D / hx2;
ncols = 5;
// if at the boundary, edit the row back to 4 nonzeros
if (i == 0) {
ncols = 4;
col[3].j = j; col[3].i = i+1; v[3] = 2.0 * D / hx2;
} else if (i == info->mx-1) {
ncols = 4;
col[3].j = j; col[3].i = i-1; v[3] = 2.0 * D / hx2;
}
ierr = MatSetValuesStencil(P,1,&row,ncols,col,v,INSERT_VALUES); CHKERRQ(ierr);
}
}
ierr = MatAssemblyBegin(P,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
ierr = MatAssemblyEnd(P,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
if (J != P) {
ierr = MatAssemblyBegin(J,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
ierr = MatAssemblyEnd(J,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
}
return 0;
}
//ENDRHSJACOBIAN
| {
"alphanum_fraction": 0.5701166543,
"avg_line_length": 38.0094339623,
"ext": "c",
"hexsha": "1095be74593f73bbc3226a87568986df0d85f8b6",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mapengfei-nwpu/p4pdes",
"max_forks_repo_path": "c/ch5/heat.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mapengfei-nwpu/p4pdes",
"max_issues_repo_path": "c/ch5/heat.c",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "706411c1e745d7f825f336dcab3a62852538eaa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mapengfei-nwpu/p4pdes",
"max_stars_repo_path": "c/ch5/heat.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2586,
"size": 8058
} |
#ifndef _EM_UTILS_H_
#define _EM_UTILS_H_ 1
#include <petsc.h>
#include <string>
std::string string_format(const char*, ...);
std::string parse_string(const std::string &s);
class LogEventHelper {
public:
LogEventHelper(PetscLogEvent ple) : ple_(ple) { PetscLogEventBegin(ple_, 0, 0, 0, 0); }
~LogEventHelper() { PetscLogEventEnd(ple_, 0, 0, 0, 0); }
private:
PetscLogEvent ple_;
};
class LogStageHelper {
public:
LogStageHelper(const std::string &name) {
PetscLogStage pls;
PetscLogStageRegister(name.c_str(), &pls);
PetscLogStagePush(pls);
}
~LogStageHelper() { PetscLogStagePop(); }
};
#endif
| {
"alphanum_fraction": 0.7033492823,
"avg_line_length": 20.2258064516,
"ext": "h",
"hexsha": "f529949e86bc5aec6d11c424dca07fd9efd227f7",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9129e28610d7fcb83a88021528575dfeaadad502",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "emfem/emfem",
"max_forks_repo_path": "src/em_utils.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9129e28610d7fcb83a88021528575dfeaadad502",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "emfem/emfem",
"max_issues_repo_path": "src/em_utils.h",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9129e28610d7fcb83a88021528575dfeaadad502",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "emfem/emfem",
"max_stars_repo_path": "src/em_utils.h",
"max_stars_repo_stars_event_max_datetime": "2021-08-03T12:22:37.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-08-03T12:22:37.000Z",
"num_tokens": 190,
"size": 627
} |
/**
*
* @file qwrapper_zlag2c.c
*
* PLASMA core_blas quark wrapper
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Mathieu Faverge
* @date 2010-11-15
* @precisions mixed zc -> ds
*
**/
#include <lapacke.h>
#include "common.h"
/***************************************************************************//**
*
**/
void QUARK_CORE_zlag2c(Quark *quark, Quark_Task_Flags *task_flags,
int m, int n, int nb,
const PLASMA_Complex64_t *A, int lda,
PLASMA_Complex32_t *B, int ldb,
PLASMA_sequence *sequence, PLASMA_request *request)
{
DAG_CORE_LAG2C;
QUARK_Insert_Task(quark, CORE_zlag2c_quark, task_flags,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(PLASMA_Complex64_t)*nb*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(PLASMA_Complex32_t)*nb*nb, B, OUTPUT,
sizeof(int), &ldb, VALUE,
sizeof(PLASMA_sequence*), &sequence, VALUE,
sizeof(PLASMA_request*), &request, VALUE,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_zlag2c_quark = PCORE_zlag2c_quark
#define CORE_zlag2c_quark PCORE_zlag2c_quark
#endif
void CORE_zlag2c_quark(Quark *quark)
{
int m;
int n;
PLASMA_Complex64_t *A;
int lda;
PLASMA_Complex32_t *B;
int ldb;
PLASMA_sequence *sequence;
PLASMA_request *request;
int info;
quark_unpack_args_8(quark, m, n, A, lda, B, ldb, sequence, request);
info = LAPACKE_zlag2c_work(LAPACK_COL_MAJOR, m, n, A, lda, B, ldb);
if (sequence->status == PLASMA_SUCCESS && info != 0)
plasma_sequence_flush(quark, sequence, request, info);
}
/***************************************************************************//**
*
**/
void QUARK_CORE_clag2z(Quark *quark, Quark_Task_Flags *task_flags,
int m, int n, int nb,
const PLASMA_Complex32_t *A, int lda,
PLASMA_Complex64_t *B, int ldb)
{
QUARK_Insert_Task(quark, CORE_clag2z_quark, task_flags,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(PLASMA_Complex32_t)*nb*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(PLASMA_Complex64_t)*nb*nb, B, INOUT,
sizeof(int), &ldb, VALUE,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_clag2z_quark = PCORE_clag2z_quark
#define CORE_clag2z_quark PCORE_clag2z_quark
#endif
void CORE_clag2z_quark(Quark *quark)
{
int m;
int n;
PLASMA_Complex32_t *A;
int lda;
PLASMA_Complex64_t *B;
int ldb;
quark_unpack_args_6(quark, m, n, A, lda, B, ldb);
LAPACKE_clag2z_work(LAPACK_COL_MAJOR, m, n, A, lda, B, ldb);
}
| {
"alphanum_fraction": 0.5096501809,
"avg_line_length": 31.8846153846,
"ext": "c",
"hexsha": "1e180f2dfec766ef6e604dfa10ebd9b6b45d82e3",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zhuangsc/Plasma-ompss1",
"max_forks_repo_path": "core_blas-qwrapper/qwrapper_zlag2c.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zhuangsc/Plasma-ompss1",
"max_issues_repo_path": "core_blas-qwrapper/qwrapper_zlag2c.c",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zhuangsc/Plasma-ompss1",
"max_stars_repo_path": "core_blas-qwrapper/qwrapper_zlag2c.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 895,
"size": 3316
} |
/* Provides the Lua Linear module. See LICENSE for license terms. */
#ifndef LUALINEAR_INCLUDED
#define LUALINEAR_INCLUDED
#include <assert.h>
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
#include <cblas.h>
/**
* Meta tables.
*/
#define LUALINEAR_VECTOR_METATABLE "linear.vector"
#define LUALINEAR_MATRIX_METATABLE "linear.matrix"
/**
* OpenMP.
*/
#define LUALINEAR_OMP_MINSIZE 2048
/**
* Vector.
*/
struct vector {
int size;
int inc;
float *values;
int ref;
};
/**
* Pushes a new vector onto the stack.
*/
inline struct vector *lualinear_newvector (lua_State *L, int size) {
struct vector *vector;
assert(size >= 1);
vector = (struct vector *)lua_newuserdata(L, sizeof(struct vector));
vector->size = size;
vector->inc = 1;
vector->values = NULL;
vector->ref = LUA_NOREF;
luaL_getmetatable(L, LUALINEAR_VECTOR_METATABLE);
lua_setmetatable(L, -2);
vector->values = (float *)calloc(size, sizeof(float));
if (vector->values == NULL) {
luaL_error(L, "cannot allocate values");
}
return vector;
}
/**
* Pushes an existing vector onto the stack.
*/
inline struct vector *lualinear_wrapvector (lua_State *L, int size,
float *values) {
struct vector *vector;
assert(size >= 1);
vector = (struct vector *)lua_newuserdata(L, sizeof(struct vector));
vector->size = size;
vector->inc = 1;
vector->values = values;
vector->ref = LUA_REFNIL;
luaL_getmetatable(L, LUALINEAR_VECTOR_METATABLE);
lua_setmetatable(L, -2);
return vector;
}
/**
* Matrix.
*/
struct matrix {
int rows;
int cols;
int ld;
CBLAS_ORDER order;
float *values;
int ref;
};
/**
* Pushes a new matrix onto the stack.
*/
inline struct matrix *lualinear_newmatrix (lua_State *L, int rows, int cols,
CBLAS_ORDER order) {
struct matrix *matrix;
assert(rows >= 1 && cols >= 1);
matrix = (struct matrix *)lua_newuserdata(L, sizeof(struct matrix));
matrix->rows = rows;
matrix->cols = cols;
matrix->ld = order == CblasRowMajor ? cols : rows;
matrix->order = order;
matrix->values = NULL;
matrix->ref = LUA_NOREF;
luaL_getmetatable(L, LUALINEAR_MATRIX_METATABLE);
lua_setmetatable(L, -2);
matrix->values = (float *)calloc((size_t)rows * cols, sizeof(float));
if (matrix->values == NULL) {
luaL_error(L, "cannot allocate values");
}
return matrix;
}
/**
* Pushes an existing matrix onto the stack-
*/
inline struct matrix *lualinear_wrapmatrix (lua_State *L, int rows, int cols,
CBLAS_ORDER order, float *values) {
struct matrix *matrix;
assert(rows >= 1 && cols >= 1);
matrix = (struct matrix *)lua_newuserdata(L, sizeof(struct matrix));
matrix->rows = rows;
matrix->cols = cols;
matrix->ld = order == CblasRowMajor ? cols : rows;
matrix->order = order;
matrix->values = values;
matrix->ref = LUA_REFNIL;
luaL_getmetatable(L, LUALINEAR_MATRIX_METATABLE);
lua_setmetatable(L, -2);
return matrix;
}
/**
* Opens the Linear module in a Lua state.
*/
int luaopen_linear (lua_State *L);
#endif /* LUALINEAR_INCLUDED */
| {
"alphanum_fraction": 0.675146771,
"avg_line_length": 22.8805970149,
"ext": "h",
"hexsha": "c5a7b2e8d7e308e108ac8a29e4cf8c43af7e2439",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T09:33:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-08-05T23:58:02.000Z",
"max_forks_repo_head_hexsha": "fcd5c3b4899723aa1d4841eb3a18e34c98561bcb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "42xel/ExponentGame",
"max_forks_repo_path": "lua-linear-master/linear.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fcd5c3b4899723aa1d4841eb3a18e34c98561bcb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "42xel/ExponentGame",
"max_issues_repo_path": "lua-linear-master/linear.h",
"max_line_length": 77,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "fcd5c3b4899723aa1d4841eb3a18e34c98561bcb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "42xel/ExponentGame",
"max_stars_repo_path": "lua-linear-master/linear.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T09:33:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-07-21T00:09:52.000Z",
"num_tokens": 803,
"size": 3066
} |
/* $Id$ */
/*--------------------------------------------------------------------*/
/*; Copyright (C) 2013 */
/*; Associated Universities, Inc. Washington DC, USA. */
/*; */
/*; 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., 675 Massachusetts Ave, Cambridge, */
/*; MA 02139, USA. */
/*; */
/*;Correspondence about this software should be addressed as follows: */
/*; Internet email: bcotton@nrao.edu. */
/*; Postal address: William Cotton */
/*; National Radio Astronomy Observatory */
/*; 520 Edgemont Road */
/*; Charlottesville, VA 22903-2475 USA */
/*--------------------------------------------------------------------*/
#include <time.h>
#include <gsl/gsl_randist.h>
#include "ObitThread.h"
#include "ObitOTFUtil.h"
/*----------------Obit: Merx mollis mortibus nuper ------------------*/
/**
* \file ObitVEGASUtil.c
* ObitOTF class utility function definitions.
*/
/*---------------Private structures----------------*/
/*---------------Private function prototypes----------------*/
/*----------------------Public functions---------------------------*/
/**
* Average the frequencies in a GBT/VEGAS OTF
* \param inVEGAS Input VEGAS, any calibration and flagging should be applied.
* \param outVEGAS Output VEGAS, must already be defined
* \param chAvg Number of channels to average, -1 => all
* \param err Error stack
*/
void ObitVEGASUtilAverage(ObitOTF *inOTF, ObitOTF *outOTF, olong chAvg,
ObitErr *err)
{
const ObitClassInfo *ParentClass;
ObitIOCode retCode;
gboolean doCalSelect, done;
olong firstRec, navg, nchanIn, nchanOut;
olong ichan, ochan, ochn, ifeed, nfeed, istok, nstok, indx, ondx;
ObitInfoType type;
ObitIOAccess access;
gint32 dim[MAXINFOELEMDIM] = {1,1,1,1,1};
ofloat sum, sumWt, *iData, *oData;
olong NPIO, iran, irec;
ObitOTFDesc *iDesc, *oDesc;
ObitHistory *inHist=NULL, *outHist=NULL;
/* Don't copy Cal and Soln or data or flag tables */
gchar *exclude[]={"OTFSoln", "OTFCal", "OTFScanData", "OTFFlag", NULL};
gchar *routine = "ObitVEGASUtilAverage";
/* error checks */
g_assert (ObitErrIsA(err));
if (err->error) return;
g_assert (ObitOTFIsA(inOTF));
g_assert (ObitOTFIsA(outOTF));
/* Input and output must be different */
Obit_return_if_fail ((!ObitOTFSame (inOTF, outOTF, err)), err,
"%s: Output cannot be the same as the input", routine);
/* deep copy any base class members */
ParentClass = ((ObitClassInfo*)inOTF->ClassInfo)->ParentClass;
g_assert ((ParentClass!=NULL) && (ParentClass->ObitCopy!=NULL));
ParentClass->ObitCopy (inOTF, outOTF, err);
outOTF->mySel = newObitOTFSel (outOTF->name);
outOTF->tableList = newObitTableList(outOTF->name);
outOTF->geom = newObitOTFArrayGeom(outOTF->name);
/* Calibration wanted? */
doCalSelect = FALSE;
ObitInfoListGetTest(inOTF->info, "doCalSelect", &type, (gint32*)dim,
&doCalSelect);
if (doCalSelect) access = OBIT_IO_ReadCal;
else access = OBIT_IO_ReadWrite;
/* Make sure NPIO the same */
NPIO = 1000;
dim[0] = 1;
ObitInfoListGetTest (inOTF->info, "nRecPIO", &type, dim, &NPIO);
ObitInfoListAlwaysPut (inOTF->info, "nRecPIO", OBIT_long, dim, &NPIO);
ObitInfoListAlwaysPut (outOTF->info, "nRecPIO", OBIT_long, dim, &NPIO);
/* Open Input Data */
retCode = ObitOTFOpen (inOTF, access, err);
if ((retCode != OBIT_IO_OK) || (err->error>0)) goto cleanup;
/* How many channels to average? Defaults to all. */
iDesc = inOTF->myDesc;
nchanIn = iDesc->inaxes[iDesc->jlocf];
if (chAvg>0) navg = chAvg;
else navg = nchanIn;
navg = MAX (1, MIN (navg, nchanIn));
nchanOut = MAX (1, (olong)(((ofloat)(nchanIn)/navg)+0.9999));
/* Number of feeds */
nfeed = iDesc->inaxes[iDesc->jlocfeed];
/* NUmber of Stokes */
nstok = iDesc->inaxes[iDesc->jlocs];
/* Copy descriptor */
outOTF->myDesc = (gpointer)ObitOTFDescCopy(iDesc, outOTF->myDesc, err);
outOTF->myDesc->nrecord = 0; /* may not copy all */
oDesc = outOTF->myDesc;
/* Averaging in frequency */
oDesc->inaxes[oDesc->jlocf] = nchanOut;
oDesc->colRepeat[oDesc->ncol-1] /= navg;
oDesc->cdelt[oDesc->jlocf] *= navg;
oDesc->crpix[oDesc->jlocf] /= navg;
ObitOTFDescIndex (oDesc);
/* copy/average Array Geometry - this time with full information
NO, VEGAS doesn't have one "detector" per frequency
outOTF->geom = ObitOTFArrayGeomAver(inOTF->geom, iDesc, outOTF->geom, oDesc, err);
if (err->error) goto cleanup; */
/* Open Output Data */
retCode = ObitOTFOpen (outOTF, OBIT_IO_WriteOnly, err) ;
if ((retCode != OBIT_IO_OK) || (err->error>0)) goto cleanup;
/* Copy any history */
inHist = newObitHistoryValue("in history", inOTF->info, err);
outHist = newObitHistoryValue("out history", outOTF->info, err);
outHist = ObitHistoryCopy (inHist, outHist, err);
if (err->error) goto cleanup;
inHist = ObitHistoryUnref(inHist);
outHist = ObitHistoryUnref(outHist);
/* Copy tables before data */
retCode = ObitOTFCopyTables (inOTF, outOTF, exclude, NULL, err);
if (err->error) goto cleanup;
/* Close and reopen input to init calibration which will have
been disturbed by the table copy */
retCode = ObitOTFClose (inOTF, err);
if (err->error) goto cleanup;
retCode = ObitOTFOpen (inOTF, access, err);
if ((retCode != OBIT_IO_OK) || (err->error>0)) goto cleanup;
/* Loop over data */
done = (retCode != OBIT_IO_OK);
while (!done) {
/* read buffer */#
retCode = ObitOTFRead (inOTF, NULL, err);
if (err->error) goto cleanup;
done = (retCode == OBIT_IO_EOF); /* done? */
if (done) break;
firstRec = inOTF->myDesc->firstRec;
iData = inOTF->buffer; /* Input data pointer */
oData = outOTF->buffer; /* Output data pointer */
/* How many? */
outOTF->myDesc->numRecBuff = inOTF->myDesc->numRecBuff;
/* Loop over buffer */
for (irec=0; irec<iDesc->numRecBuff; irec++) {
/* Copy random (descriptive parameters */
for (iran=0; iran<iDesc->numDesc; iran++) oData[iran] = iData[iran];
/* Average input to output */
/* Loop over Stokes */
for (istok=0; istok<nstok; istok++) {
/* Loop over Feed */
for (ifeed=0; ifeed<nfeed; ifeed++) {
/* Outer loop over channel */
ochn = 0; /* output channel 0-rel index */
for (ochan=0; ochan<nchanIn; ochan+=navg) {
/* Inner frequency loop summing */
sum = sumWt = 0.0;
indx = iDesc->ilocdata + istok*iDesc->incs + ifeed*iDesc->incfeed;
ondx = oDesc->ilocdata + istok*oDesc->incs + ifeed*oDesc->incfeed;
for (ichan=ochan; ichan<ochan+navg; ichan++) {
sum += iData[indx+ichan*iDesc->incf] * iData[indx+ichan*iDesc->incf+1];
sumWt += iData[indx+ichan*iDesc->incf+1];
} /* end inner loop */
/* Save average to outout */
if (sumWt>0.0) {
oData[ondx+ochn*oDesc->incf] = sum/sumWt;
oData[ondx+ochn*oDesc->incf+1] = sumWt;
} else { /* bad */
oData[ondx+ochn*oDesc->incf] = 0.0;
oData[ondx+ochn*oDesc->incf+1] = 0.0;
}
ochn++;
} /* end outer channel loop */
} /* end feed loop */
} /* end Stokes loop */
iData += iDesc->lrec; /* Update buffer pointers */
oData += oDesc->lrec;
} /* end loop over buffer */
/* Write buffer */
if (outOTF->myDesc->numRecBuff>0) retCode = ObitOTFWrite (outOTF, NULL, err);
if (err->error) goto cleanup;
} /* end loop over file */
cleanup:
/* unset output buffer */
outOTF->buffer = NULL;
outOTF->bufferSize = 0;
retCode = ObitOTFClose (outOTF, err); /* Close output */
/* Close input */
retCode = ObitOTFClose (inOTF, err);
/* cleanup */
if (err->error) Obit_traceback_msg (err, routine, inOTF->name);
} /* end ObitOTFUtilAverage */
| {
"alphanum_fraction": 0.5841540334,
"avg_line_length": 38.9525862069,
"ext": "c",
"hexsha": "32ef3157d19be3c00749f6adf71cace65aa2cc2e",
"lang": "C",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2022-03-31T12:16:08.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-29T15:12:32.000Z",
"max_forks_repo_head_hexsha": "e4ce6029e9beb2a8c0316ee81ea710b66b2b7986",
"max_forks_repo_licenses": [
"Linux-OpenIB"
],
"max_forks_repo_name": "sarrvesh/Obit",
"max_forks_repo_path": "ObitSystem/ObitSD/src/ObitVEGASUtil.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e4ce6029e9beb2a8c0316ee81ea710b66b2b7986",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Linux-OpenIB"
],
"max_issues_repo_name": "sarrvesh/Obit",
"max_issues_repo_path": "ObitSystem/ObitSD/src/ObitVEGASUtil.c",
"max_line_length": 84,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "e4ce6029e9beb2a8c0316ee81ea710b66b2b7986",
"max_stars_repo_licenses": [
"Linux-OpenIB"
],
"max_stars_repo_name": "sarrvesh/Obit",
"max_stars_repo_path": "ObitSystem/ObitSD/src/ObitVEGASUtil.c",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T01:08:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-26T06:53:08.000Z",
"num_tokens": 2728,
"size": 9037
} |
/*
ODE: a program to get optime Runge-Kutta and multi-steps methods.
Copyright 2011-2019, Javier Burguete Tolosa.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY Javier Burguete Tolosa ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL Javier Burguete Tolosa OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file rk_6_4.c
* \brief Source file to optimize Runge-Kutta 6 steps 4th order methods.
* \author Javier Burguete Tolosa.
* \copyright Copyright 2011-2019.
*/
#define _GNU_SOURCE
#include <string.h>
#include <math.h>
#include <libxml/parser.h>
#include <glib.h>
#include <libintl.h>
#include <gsl/gsl_rng.h>
#include "config.h"
#include "utils.h"
#include "optimize.h"
#include "rk.h"
#include "rk_6_3.h"
#define DEBUG_RK_6_3 0 ///< macro to debug.
/**
* Function to obtain the coefficients of a 6 steps 3rd order Runge-Kutta
* method.
*/
int
rk_tb_6_3 (Optimize * optimize) ///< Optimize struct.
{
long double A[3], B[3], C[3], D[3];
long double *tb, *r;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3: start\n");
#endif
tb = optimize->coefficient;
r = optimize->random_data;
t6 (tb) = 1.L;
t1 (tb) = r[0];
t2 (tb) = r[1];
b21 (tb) = r[2];
t3 (tb) = r[3];
b31 (tb) = r[4];
b32 (tb) = r[5];
t4 (tb) = r[6];
b41 (tb) = r[7];
b42 (tb) = r[8];
b43 (tb) = r[9];
t5 (tb) = r[10];
b51 (tb) = r[11];
b52 (tb) = r[12];
b53 (tb) = r[13];
b54 (tb) = r[14];
b65 (tb) = r[15];
b64 (tb) = r[16];
A[0] = t1 (tb);
B[0] = t2 (tb);
C[0] = t3 (tb);
D[0] = 0.5L - b64 (tb) * t4 (tb) - b65 (tb) * t5 (tb);
A[1] = A[0] * t1 (tb);
B[1] = B[0] * t2 (tb);
C[1] = C[0] * t3 (tb);
D[1] = 1.L / 3.L - b64 (tb) * sqr (t4 (tb)) - b65 (tb) * sqr (t5 (tb));
A[2] = 0.L;
B[2] = b21 (tb) * t1 (tb);
C[2] = b31 (tb) * t1 (tb) + b32 (tb) * t2 (tb);
D[2] = 1.L / 6.L - b64 (tb) * (b41 (tb) * t1 (tb) + b42 (tb) * t2 (tb)
+ b43 (tb) * t3 (tb))
- b65 (tb) * (b51 (tb) * t1 (tb) + b52 (tb) * t2 (tb)
+ b53 (tb) * t3 (tb) + b54 (tb) * t4 (tb));
solve_3 (A, B, C, D);
if (isnan (D[0]) || isnan (D[1]) || isnan (D[2]))
return 0;
b63 (tb) = D[2];
b62 (tb) = D[1];
b61 (tb) = D[0];
rk_b_6 (tb);
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3: end\n");
#endif
return 1;
}
/**
* Function to obtain the coefficients of a 6 steps 3rd order, 4th order in
* equations depending only in time, Runge-Kutta method.
*/
int
rk_tb_6_3t (Optimize * optimize) ///< Optimize struct.
{
long double A[4], B[4], C[4], D[4], E[4];
long double *tb, *r;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3t: start\n");
#endif
tb = optimize->coefficient;
r = optimize->random_data;
t6 (tb) = 1.L;
t1 (tb) = r[0];
t2 (tb) = r[1];
b21 (tb) = r[2];
t3 (tb) = r[3];
b31 (tb) = r[4];
b32 (tb) = r[5];
t4 (tb) = r[6];
b41 (tb) = r[7];
b42 (tb) = r[8];
b43 (tb) = r[9];
t5 (tb) = r[10];
b51 (tb) = r[11];
b52 (tb) = r[12];
b53 (tb) = r[13];
b54 (tb) = r[14];
b65 (tb) = r[15];
A[0] = t1 (tb);
B[0] = t2 (tb);
C[0] = t3 (tb);
D[0] = t4 (tb);
E[0] = 0.5L - b65 (tb) * t5 (tb);
A[1] = A[0] * t1 (tb);
B[1] = B[0] * t2 (tb);
C[1] = C[0] * t3 (tb);
D[1] = D[0] * t4 (tb);
E[1] = 1.L / 3.L - b65 (tb) * sqr (t5 (tb));
A[2] = A[1] * t1 (tb);
B[2] = B[1] * t2 (tb);
C[2] = C[1] * t3 (tb);
D[2] = D[1] * t4 (tb);
E[2] = 0.25L - b65 (tb) * sqr (t5 (tb)) * t5 (tb);
A[3] = 0.L;
B[3] = b21 (tb) * t1 (tb);
C[3] = b31 (tb) * t1 (tb) + b32 (tb) * t2 (tb);
D[3] = b41 (tb) * t1 (tb) + b42 (tb) * t2 (tb) + b43 (tb) * t3 (tb);
E[3] = 1.L / 6.L - b65 (tb) * (b51 (tb) * t1 (tb) + b52 (tb) * t2 (tb)
+ b53 (tb) * t3 (tb) + b54 (tb) * t4 (tb));
solve_4 (A, B, C, D, E);
if (isnan (E[0]) || isnan (E[1]) || isnan (E[2]) || isnan (E[3]))
return 0;
b64 (tb) = E[3];
b63 (tb) = E[2];
b62 (tb) = E[1];
b61 (tb) = E[0];
rk_b_6 (tb);
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3t: end\n");
#endif
return 1;
}
/**
* Function to obtain the coefficients of a 6 steps 2nd-3rd order Runge-Kutta
* pair.
*/
int
rk_tb_6_3p (Optimize * optimize) ///< Optimize struct.
{
long double *tb;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3p: start\n");
#endif
if (!rk_tb_6_3 (optimize))
return 0;
tb = optimize->coefficient;
e51 (tb) = 0.5L / t1 (tb);
e52 (tb) = e53 (tb) = 0.L;
rk_e_6 (tb);
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3p: end\n");
#endif
return 1;
}
/**
* Function to obtain the coefficients of a 6 steps 2nd-3rd order, 3rd-4th order
* in equations depending only in time, Runge-Kutta pair.
*/
int
rk_tb_6_3tp (Optimize * optimize) ///< Optimize struct.
{
long double *tb;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3tp: start\n");
#endif
if (!rk_tb_6_3t (optimize))
return 0;
tb = optimize->coefficient;
e63 (tb) = e64 (tb) = 0.L;
e62 (tb) = (1.L / 3.L - 0.5L * t1 (tb)) / (t2 (tb) * (t2 (tb) - t1 (tb)));
if (isnan (e62 (tb)))
return 0;
e61 (tb) = (0.5L - e52 (tb) * t2 (tb)) / t1 (tb);
if (isnan (e61 (tb)))
return 0;
rk_e_6 (tb);
#if DEBUG_RK_6_3
fprintf (stderr, "rk_tb_6_3tp: end\n");
#endif
return 1;
}
/**
* Function to calculate the objective function of a 6 steps 3rd order
* Runge-Kutta method.
*
* \return objective function value.
*/
long double
rk_objective_tb_6_3 (RK * rk) ///< RK struct.
{
long double *tb;
long double o;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3: start\n");
#endif
tb = rk->tb->coefficient;
o = fminl (0.L, b20 (tb));
if (b30 (tb) < 0.L)
o += b30 (tb);
if (b40 (tb) < 0.L)
o += b40 (tb);
if (b50 (tb) < 0.L)
o += b50 (tb);
if (b60 (tb) < 0.L)
o += b60 (tb);
if (b61 (tb) < 0.L)
o += b61 (tb);
if (b62 (tb) < 0.L)
o += b62 (tb);
if (b63 (tb) < 0.L)
o += b63 (tb);
if (b64 (tb) < 0.L)
o += b64 (tb);
if (o < 0.L)
{
o = 40.L - o;
goto end;
}
o = 30.L
+ fmaxl (1.L,
fmaxl (t1 (tb),
fmaxl (t2 (tb),
fmaxl (t3 (tb), fmaxl (t4 (tb), t5 (tb))))));
if (rk->strong)
{
rk_bucle_ac (rk);
o = fminl (o, *rk->ac0->optimal);
}
end:
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3: optimal=%Lg\n", o);
fprintf (stderr, "rk_objective_tb_6_3: end\n");
#endif
return o;
}
/**
* Function to calculate the objective function of a 6 steps 3rd order, 4th
* order in equations depending only in time, Runge-Kutta method.
*
* \return objective function value.
*/
long double
rk_objective_tb_6_3t (RK * rk) ///< RK struct.
{
long double *tb;
long double o;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3t: start\n");
#endif
tb = rk->tb->coefficient;
o = fminl (0.L, b20 (tb));
if (b30 (tb) < 0.L)
o += b30 (tb);
if (b40 (tb) < 0.L)
o += b40 (tb);
if (b50 (tb) < 0.L)
o += b50 (tb);
if (b60 (tb) < 0.L)
o += b60 (tb);
if (b61 (tb) < 0.L)
o += b61 (tb);
if (b62 (tb) < 0.L)
o += b62 (tb);
if (b63 (tb) < 0.L)
o += b63 (tb);
if (b64 (tb) < 0.L)
o += b64 (tb);
if (o < 0.L)
{
o = 40.L - o;
goto end;
}
o = 30.L
+ fmaxl (1.L,
fmaxl (t1 (tb),
fmaxl (t2 (tb),
fmaxl (t3 (tb), fmaxl (t4 (tb), t5 (tb))))));
if (rk->strong)
{
rk_bucle_ac (rk);
o = fminl (o, *rk->ac0->optimal);
}
end:
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3t: optimal=%Lg\n", o);
fprintf (stderr, "rk_objective_tb_6_3t: end\n");
#endif
return o;
}
/**
* Function to calculate the objective function of a 6 steps 2nd-3rd order
* Runge-Kutta pair.
*
* \return objective function value.
*/
long double
rk_objective_tb_6_3p (RK * rk) ///< RK struct.
{
long double *tb;
long double o;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3p: start\n");
#endif
tb = rk->tb->coefficient;
o = fminl (0.L, b20 (tb));
if (b30 (tb) < 0.L)
o += b30 (tb);
if (b40 (tb) < 0.L)
o += b40 (tb);
if (b50 (tb) < 0.L)
o += b50 (tb);
if (b60 (tb) < 0.L)
o += b60 (tb);
if (b61 (tb) < 0.L)
o += b61 (tb);
if (b62 (tb) < 0.L)
o += b62 (tb);
if (b63 (tb) < 0.L)
o += b63 (tb);
if (b64 (tb) < 0.L)
o += b64 (tb);
if (e60 (tb) < 0.L)
o += e60 (tb);
if (e61 (tb) < 0.L)
o += e61 (tb);
if (o < 0.L)
{
o = 40.L - o;
goto end;
}
o = 30.L
+ fmaxl (1.L,
fmaxl (t1 (tb),
fmaxl (t2 (tb),
fmaxl (t3 (tb), fmaxl (t4 (tb), t5 (tb))))));
if (rk->strong)
{
rk_bucle_ac (rk);
o = fminl (o, *rk->ac0->optimal);
}
end:
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3p: optimal=%Lg\n", o);
fprintf (stderr, "rk_objective_tb_6_3p: end\n");
#endif
return o;
}
/**
* Function to calculate the objective function of a 6 steps 2nd-3rd order,
* 3rd-4th order in equations depending only in time, Runge-Kutta pair.
*
* \return objective function value.
*/
long double
rk_objective_tb_6_3tp (RK * rk) ///< RK struct.
{
long double *tb;
long double o;
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3tp: start\n");
#endif
tb = rk->tb->coefficient;
o = fminl (0.L, b20 (tb));
if (b30 (tb) < 0.L)
o += b30 (tb);
if (b40 (tb) < 0.L)
o += b40 (tb);
if (b50 (tb) < 0.L)
o += b50 (tb);
if (b60 (tb) < 0.L)
o += b60 (tb);
if (b61 (tb) < 0.L)
o += b61 (tb);
if (b62 (tb) < 0.L)
o += b62 (tb);
if (b63 (tb) < 0.L)
o += b63 (tb);
if (b64 (tb) < 0.L)
o += b64 (tb);
if (e60 (tb) < 0.L)
o += e60 (tb);
if (e61 (tb) < 0.L)
o += e61 (tb);
if (e62 (tb) < 0.L)
o += e62 (tb);
if (o < 0.L)
{
o = 40.L - o;
goto end;
}
o = 30.L
+ fmaxl (1.L,
fmaxl (t1 (tb),
fmaxl (t2 (tb),
fmaxl (t3 (tb), fmaxl (t4 (tb), t5 (tb))))));
if (rk->strong)
{
rk_bucle_ac (rk);
o = fminl (o, *rk->ac0->optimal);
}
end:
#if DEBUG_RK_6_3
fprintf (stderr, "rk_objective_tb_6_3tp: optimal=%Lg\n", o);
fprintf (stderr, "rk_objective_tb_6_3tp: end\n");
#endif
return o;
}
| {
"alphanum_fraction": 0.541865817,
"avg_line_length": 24.8307692308,
"ext": "c",
"hexsha": "b235114197008a7bc99944f74ff838f73ce13f0c",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "463b8402ed4aac140a4c4ca2295a69dcce98b061",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "jburguete/ode",
"max_forks_repo_path": "rk_6_3.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "463b8402ed4aac140a4c4ca2295a69dcce98b061",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "jburguete/ode",
"max_issues_repo_path": "rk_6_3.c",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "463b8402ed4aac140a4c4ca2295a69dcce98b061",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "jburguete/ode",
"max_stars_repo_path": "rk_6_3.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4576,
"size": 11298
} |
/*
* parameters.h
* Spike
*
* Created by Ben Evans on 18/08/2008.
* Copyright 2008 University of Oxford. All rights reserved.
*
*/
#ifndef _PARAMETERS_H
#define _PARAMETERS_H
#include <stdbool.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_version.h>
typedef int tstep; // Signed to allow spikeTimes[0] = -BIG //long long
typedef unsigned char uchar;
struct SIMULATION {
bool Xgrid;
tstep tally;
tstep ptTS;
tstep trainTS;
tstep testTS;
tstep totTS;
float minTau;
double start;
double elapsed;
double realSecPerSimSec;
} SIM;
typedef struct DIMENSIONS {
int nRows;
int nCols;
int nFilt;
} DIM;
//extern SIMULATION SIM;
/*typedef enum {
Off,
//Uniform,
Gaussian
} NOISE;*/
typedef enum {
MinD,
ConstD,
UniformD,
GaussD,
SOMD
} DELAY;
typedef enum {
//Zero,
Constant, // Zero set using appropriate Dg modifier
Uniform,
Gaussian,
SOM
} INITIALISATION;
typedef enum {
None,
MaintainLength,
MaintainSum
} NORMALISATION;
/********************** Main Network Parmeters *************************/
// Update read_parameters and defaults.m when a new parameter is added
typedef struct {
// Simulation
float DT;
bool initialised; // Internal
int loops;
bool pretrain;// = true;
bool train;// = true;
bool priorPhases;
bool isolateEfE;
bool trainPause;
bool noise; // int
float noiseScale;
float SigmaE;
float SigmaI;
NORMALISATION normalise;
int nRecordsPL;// = 0;
int nRecords;
int * vRecords;
//float TotalTime;
float MaxTime;
float EpochTime;
float TestTime;
int EpochMS;
int TestMS;
int TotalMS;
int RecordMS;
//tstep TotalTS;
int TSperMS;
int spkBuffer;
//int inpSpkBuff;
bool printConnections;
bool saveInputSpikes;
bool probConnect;
bool loadWeights;
// Stimuli
char * imgDir;
char * imgList;
bool randStimOrder;// = true;
bool randTransOrder;
bool randTransDirection;
bool interleaveTrans;
bool localRep;// = true;
float current;// = 1.25e-9;
float currentSpread;
bool loadStimuli;
bool stimGroups;
int nBG; // # shared between groups
int nWG; // # specific within each group
int nGroups;
int nStimuli;
int nTransPS;
bool newTestSet;
int M; // Degree of training i.e. train with M of the NCK
int K; // Number of stimuli presented simultaneously
//int nTestGroups;
int nTestStimuli;
int nTestTransPS;
float transP_Train;
float transP_Test;
int shift;
int nFiringNeurons;
float a; // Sparseness of stimuli
bool useFilteredImages;
bool gabor;
int nScales;
int * vScales;
int nOrients;
int * vOrients;
int nPhases;
int * vPhases;
int sInputs;
int nRows;
int nCols;
// Network
int nLayers;// = 2;
int nWLayers;
bool inputInhib;
int nExcit;// = 120;
int * vExcit;
int LvExcit;
int nSynEfE;
float * pCnxEfE;
int LpEfE;
int nSynElE;
float * pCnxElE;
int LpElE;
int nSynIE;
float * pCnxIE;
int LpIE;
int nInhib;// = 40;
float rInhib;
int * vInhib;
int LvInhib;
int nSynEI;
float * pCnxEI;
int LpEI;
int nSynII;
float * pCnxII;
int LpII;
INITIALISATION initEfE;
float iEfE;
bool axonDelay; //DELAY axonDelay;
DELAY delayEfE;
DELAY delayElE;
DELAY delayEI;
float d_const;
float d_min;
float d_max;
float d_mean;
float d_sd;
float spatialScale;
float condSpeed;
float maxDelay;
bool SOM;
bool SOMinput;
float SOMsigE;
float SOMsigI;
float SOMclip;
//float SOMstrE;
//float SOMstrI;
bool trainEfE; // Internal var modified through isolateEfE
bool trainElE;
INITIALISATION initElE;
float iElE;
DIM * layDim;
int * vSquare;
// Cell bodies
float capE;// = 2.0e-10;
float capI;// = 10.0e-12;
float gLeakE;// = 10.0e-9;
float gLeakI;// = 5.0e-9;
float VrestE;
float VrestI;
float VhyperE;
float VhyperI;
float ThreshE;
float ThreshI;
float VrevE;
float VrevI;
float refract;// = 0.002
bool adaptation;
float alphaCa;
float tauCa;
float gAHP;
float VK;
// Synapses (afferent axons)
bool noSTDPdelay;
float alphaC;// = 0.5;
float tauC;// = 0.005;
float alphaD;// = 0.5;
float tauD;// = 0.009;
float learnR;// = 0.1;
float DgEfE; //modEf; // alter the strength of Excit f-f synapses
//float tauEfE;// tauEE = 0.01;
float DgElE;//Dg_ElE
//float tauElE;
float tauEE;
float DgIE;//Dg_IE = 0.5;
float tauIE;// = 0.001
float DgEI;//Dg_EI = 0.5;
float tauEI;// = 0.001;
float DgII;//Dg_II = 0.5;
float tauII;// = 0.001;
float gMax;// = 48.0e-10;
} PARAMS;
//PARAMS * mp;
extern PARAMS * mp;
extern gsl_rng * mSeed;
extern gsl_rng ** states;
#endif
| {
"alphanum_fraction": 0.6125322229,
"avg_line_length": 20.2530120482,
"ext": "h",
"hexsha": "6441fd0a274eeff83f572d05d0927da15886d73b",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2019-04-11T15:00:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-05-10T20:43:14.000Z",
"max_forks_repo_head_hexsha": "de7beeece36f660ee3f82d7ff0cb1094a4b35cb8",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bdevans/spike",
"max_forks_repo_path": "source/parameters.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "de7beeece36f660ee3f82d7ff0cb1094a4b35cb8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "bdevans/spike",
"max_issues_repo_path": "source/parameters.h",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "de7beeece36f660ee3f82d7ff0cb1094a4b35cb8",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bdevans/spike",
"max_stars_repo_path": "source/parameters.h",
"max_stars_repo_stars_event_max_datetime": "2019-11-14T13:59:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-14T13:59:47.000Z",
"num_tokens": 1568,
"size": 5043
} |
#pragma once
#include <imageview/ContinuousImageView.h>
#include <imageview/ImageView.h>
#include <gsl/assert>
namespace imageview {
template <class PixelFormat, bool Mutable>
constexpr ImageView<PixelFormat, Mutable> crop(ImageView<PixelFormat, Mutable> image, unsigned int first_row,
unsigned int first_column, unsigned int num_rows,
unsigned int num_columns) {
Expects(first_row <= image.height());
Expects(first_column <= image.width());
Expects(first_row + num_rows <= image.height());
Expects(first_column + num_columns <= image.width());
const std::size_t data_offset = (first_row * image.stride() + first_column) * PixelFormat::kBytesPerPixel;
const std::size_t new_data_size =
(num_rows == 0) ? 0 : ((num_rows - 1) * image.stride() + num_columns) * PixelFormat::kBytesPerPixel;
const auto data_new = image.data().subspan(data_offset, new_data_size);
return ImageView<PixelFormat>(num_rows, num_columns, image.stride(), data_new, image.pixelFormat());
}
template <class PixelFormat, bool Mutable>
constexpr ImageView<PixelFormat, Mutable> crop(ContinuousImageView<PixelFormat, Mutable> image, unsigned int first_row,
unsigned int first_column, unsigned int num_rows,
unsigned int num_columns) {
return crop(ImageView<PixelFormat, Mutable>(image), first_column, first_column, num_rows, num_columns);
}
} // namespace imageview
| {
"alphanum_fraction": 0.6722472634,
"avg_line_length": 47.0606060606,
"ext": "h",
"hexsha": "b1d85aff4478ae03ed08f559259cc9e954eef256",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "817e92ac1dcbffc7fb0ebb11afe4ee9836f37df0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alexanderbelous/imageview",
"max_forks_repo_path": "include/imageview/ImageViewUtils.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "817e92ac1dcbffc7fb0ebb11afe4ee9836f37df0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alexanderbelous/imageview",
"max_issues_repo_path": "include/imageview/ImageViewUtils.h",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "817e92ac1dcbffc7fb0ebb11afe4ee9836f37df0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alexanderbelous/imageview",
"max_stars_repo_path": "include/imageview/ImageViewUtils.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 317,
"size": 1553
} |
/*! \file rho.h
\brief 電子密度ρ(r)を求めるクラスの宣言
Copyright © 2015 @dc1394 All Rights Reserved.
This software is released under the BSD 2-Clause License.
*/
#include "data.h"
#include "property.h"
#include <memory> // for std::unique_ptr
#include <vector> // for std::vector
#include <gsl/gsl_spline.h> // for gsl_interp_accel, gsl_interp_accel_free, gsl_spline, gsl_spline_free
namespace schrac {
//! A class.
/*!
電子密度ρ(r)を求めるクラス
*/
class Rho final {
// #region コンストラクタ・デストラクタ
public:
//! A constructor.
/*!
唯一のコンストラクタ
\param pdiffdata 微分方程式のデータオブジェクト
*/
Rho(std::shared_ptr<DiffData> const & pdiffdata);
//! A destructor.
/*!
デフォルトデストラクタ
*/
~Rho() = default;
// #region メンバ関数
//! A public member function.
/*!
現在の電子密度ρ(r)で初期化する
*/
void init();
//! A public member function (const).
/*!
電子密度ρ(r)を返す
\param r rの値
\return ρ(r)の値
*/
double operator()(double r) const;
//! A public member function (const).
/*!
新しい電子密度ρnew(r)と、電子密度ρ(r)を一次混合する
\param rhonew 新しい電子密度ρnew(r)
*/
void rhomix(dvector const & rhonew);
// #endregion メンバ関数
// #region プロパティ
public:
//! A property.
/*!
電子密度が格納された可変長配列へのプロパティ
*/
Property< std::vector<double> > const PRho;
// #endregion プロパティ
// #region メンバ変数
private:
//! A private member variable.
/*!
gsl_interp_accelへのスマートポインタ
*/
std::unique_ptr<gsl_interp_accel, decltype(&gsl_interp_accel_free)> const acc_;
//! A private member variable.
/*!
データオブジェクト
*/
std::shared_ptr<DiffData> pdiffdata_;
//! A private member variable.
/*!
密度ρ(r)
*/
std::vector<double> rho_;
//! A private member variable.
/*!
gsl_splineへのスマートポインタ
*/
std::unique_ptr<gsl_spline, decltype(&gsl_spline_free)> const spline_;
// #endregion メンバ変数
// #region 禁止されたコンストラクタ・メンバ関数
//! A private constructor (deleted).
/*!
デフォルトコンストラクタ(禁止)
*/
Rho() = delete;
//! A private copy constructor (deleted).
/*!
コピーコンストラクタ(禁止)
*/
Rho(Rho const &) = delete;
//! A private member function (deleted).
/*!
operator=()の宣言(禁止)
\param コピー元のオブジェクト(未使用)
\return コピー元のオブジェクト
*/
Rho & operator=(Rho const &) = delete;
// #endregion 禁止されたコンストラクタ・メンバ関数
};
}
| {
"alphanum_fraction": 0.5047551955,
"avg_line_length": 22.5317460317,
"ext": "h",
"hexsha": "ba4d70ce1105c4afc575f247d6edaddf690dde72",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6292f61f3be3465459f216b0b71d4b87138cff93",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "dc1394/schrac",
"max_forks_repo_path": "src/rho.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6292f61f3be3465459f216b0b71d4b87138cff93",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "dc1394/schrac",
"max_issues_repo_path": "src/rho.h",
"max_line_length": 103,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "6292f61f3be3465459f216b0b71d4b87138cff93",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "dc1394/Schrac",
"max_stars_repo_path": "src/rho.h",
"max_stars_repo_stars_event_max_datetime": "2021-12-04T07:10:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-31T23:35:05.000Z",
"num_tokens": 916,
"size": 2839
} |
#ifndef _LOGIT_H
#define _LOGIT_H
#include <vector>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
class logit
{
private:
gsl_vector *y; // response vector
gsl_matrix *X; // observation matrix
size_t n; // sample size;
size_t p; // number of parameters (including intercept)
double psi; // dispersion
bool free_data; // depend on different constructors
gsl_vector *beta;
gsl_vector *Jbeta;
gsl_vector *pvalue;
public:
logit(gsl_vector *yv, gsl_matrix *Xv);
logit(const std::vector<double> & yv, const std::vector<std::vector<double> > Xv);
~logit();
void fit();
double calculate_pi(gsl_vector* xi) const;
double calculate_err(const gsl_vector* beta2) const;
double calculate_err() const;
int calculate_J(gsl_matrix* J) const;
int calculate_U(gsl_vector* U) const;
void display(gsl_matrix* m) const;
void displayv(gsl_vector* v) const;
}; //logit
#endif // _LOGIT_H
| {
"alphanum_fraction": 0.6818181818,
"avg_line_length": 23.0476190476,
"ext": "h",
"hexsha": "d5ecb3312210dd59a8239590abd6cbf70187e2d1",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "86d8c4846ed56a27ad8a9f35d9f1229fab704912",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "szcf-weiya/gsl_lm",
"max_forks_repo_path": "logit/logit.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "86d8c4846ed56a27ad8a9f35d9f1229fab704912",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "szcf-weiya/gsl_lm",
"max_issues_repo_path": "logit/logit.h",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "86d8c4846ed56a27ad8a9f35d9f1229fab704912",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "szcf-weiya/gsl_lm",
"max_stars_repo_path": "logit/logit.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 267,
"size": 968
} |
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include <gsl/gsl>
#include "core/optimizer/graph_transformer.h"
#include "orttraining/core/optimizer/graph_transformer_config.h"
#include "orttraining/core/session/training_session.h"
namespace onnxruntime {
struct FreeDimensionOverride;
namespace training {
namespace transformer_utils {
/** Generates all pre-training transformers for this level. */
std::vector<std::unique_ptr<GraphTransformer>> GeneratePreTrainingTransformers(
TransformerLevel level,
const std::unordered_set<std::string>& weights_to_train,
const TrainingGraphTransformerConfiguration& config,
const IExecutionProvider& execution_provider, // required for constant folding
const std::unordered_set<std::string>& rules_and_transformers_to_disable = {});
/** Generates all predefined (both rule-based and non-rule-based) transformers for this level.
If transformers_and_rules_to_enable is not empty, it returns the intersection between the predefined transformers/rules
and the transformers_and_rules_to_enable. */
InlinedVector<std::unique_ptr<GraphTransformer>> GenerateTransformers(
TransformerLevel level,
const std::unordered_set<std::string>& weights_to_train,
gsl::span<const FreeDimensionOverride> free_dimension_overrides,
const InlinedHashSet<std::string>& rules_and_transformers_to_disable = {});
} // namespace transformer_utils
} // namespace training
} // namespace onnxruntime
| {
"alphanum_fraction": 0.7939829954,
"avg_line_length": 40.2368421053,
"ext": "h",
"hexsha": "d0bba49746315c08117874959f7658c0e4009664",
"lang": "C",
"max_forks_count": 140,
"max_forks_repo_forks_event_max_datetime": "2019-05-06T18:02:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T21:15:28.000Z",
"max_forks_repo_head_hexsha": "3c5853dcbc9d5dda2476afa8c6105802d2b8e53d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "SiriusKY/onnxruntime",
"max_forks_repo_path": "orttraining/orttraining/core/optimizer/graph_transformer_utils.h",
"max_issues_count": 440,
"max_issues_repo_head_hexsha": "3c5853dcbc9d5dda2476afa8c6105802d2b8e53d",
"max_issues_repo_issues_event_max_datetime": "2019-05-06T20:47:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-12-03T21:09:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "SiriusKY/onnxruntime",
"max_issues_repo_path": "orttraining/orttraining/core/optimizer/graph_transformer_utils.h",
"max_line_length": 124,
"max_stars_count": 669,
"max_stars_repo_head_hexsha": "3c5853dcbc9d5dda2476afa8c6105802d2b8e53d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "SiriusKY/onnxruntime",
"max_stars_repo_path": "orttraining/orttraining/core/optimizer/graph_transformer_utils.h",
"max_stars_repo_stars_event_max_datetime": "2019-05-06T19:42:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-12-03T22:00:31.000Z",
"num_tokens": 305,
"size": 1529
} |
/*
Copyright (c) 2003-2008 Rudi Cilibrasi, Rulers of the RHouse
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE RULERS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE RULERS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#include <stdio.h>
#include <string.h>
#if OPENMP_ENABLED
#include <omp.h>
#endif
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
#include <glib.h>
#include <glib/gstdio.h>
//#include <gsl/gsl_cblas.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_linalg.h>
#include <libintl.h>
#include <unistd.h>
#include "complearn/util.h"
#define _(O) gettext(O)
void complearn_mrbreaker(void)
{
printf("break!\n");
}
int complearn_make_directory_if_necessary(const char *name)
{
return g_mkdir_with_parents(name, 0700);
}
char *complearn_get_hostname()
{
static char *answer;
if (answer == NULL) {
static char buf[1024];
#ifdef __MINGW32__
strcpy(buf, "localhost");
#else
gethostname(buf, sizeof(buf));
#endif
buf[sizeof(buf)-1] = '\0';
answer = buf;
}
return g_strdup(answer);
}
int complearn_get_pid(void)
{
return getpid();
}
GSList *complearn_read_directory_of_files(const char *dirname)
{
GError *err = NULL;
GSList *result = NULL;
GDir *d = g_dir_open(dirname, 0, &err);
if (err)
g_error(_("Cannot open directory %s"), dirname);
const char *n;
while ( (n = g_dir_read_name(d)) ) {
char *cur = g_build_filename(dirname, n, NULL);
if (g_file_test(cur, G_FILE_TEST_IS_REGULAR)) {
result = g_slist_append(result, complearn_new_arg(complearn_read_whole_file(cur),cur));
}
g_free(cur);
}
g_dir_close(d);
return result;
}
static GSList *complearn_read_list_of_files_or_strings(const char *filename, int isfiles)
{
GIOChannel *in;
GError *err = NULL;
GSList *result = NULL;
in = g_io_channel_new_file(filename, "r", &err);
if (err)
g_error(_("Cannot open file %s"), filename);
for (;;) {
GIOStatus s;
gsize tpos;
err = NULL;
GString *block = g_string_new("");
s = g_io_channel_read_line_string(in, block, &tpos, &err);
if (s == G_IO_STATUS_EOF)
break;
if (err != NULL)
g_error(_("Cannot read line from file %s: %s"), filename, err->message);
g_string_truncate(block, tpos);
GString *tokeep;
tokeep = (isfiles != 0) ? complearn_read_whole_file(block->str) : g_string_new_len(block->str, block->len);
result = g_slist_append(result, complearn_new_arg(tokeep, block->str));
}
g_io_channel_close(in);
return result;
}
GSList *complearn_read_list_of_files(const char *filename)
{
return complearn_read_list_of_files_or_strings(filename, 1);
}
GSList *complearn_read_list_of_strings(const char *filename)
{
return complearn_read_list_of_files_or_strings(filename, 0);
}
GString *complearn_read_whole_file_ptr(FILE *fp)
{
GString *result = g_string_new("");
char buf[512];
int rl;
while ( (rl = fread(buf, 1, 512, fp)) == 512)
g_string_append_len(result, buf, rl);
if (rl > 0)
g_string_append_len(result, buf, rl);
return result;
}
char *complearn_chdir(const char *newdir)
{
char *retval = g_get_current_dir();
int rv;
rv = g_chdir(newdir);
if (rv != 0) {
g_error(_("Cannot change directory to %s"), newdir);
}
return retval;
}
int complearn_remove_directory_recursively(const char *dirname, int f_err_out)
{
GError *err = NULL;
int result = 0;
GDir *d = g_dir_open(dirname, 0, &err);
if ( (err) ) {
if (f_err_out)
g_error(_("Cannot open directory %s. Error: %s"), dirname, err->message);
else
return 1;
}
const char *n;
while ( (n = g_dir_read_name(d)) ) {
char *cur = g_build_filename(dirname, n, NULL);
if (g_file_test(cur, G_FILE_TEST_IS_REGULAR))
g_unlink(cur);
g_free(cur);
}
g_dir_close(d);
result = g_rmdir(dirname);
return result;
}
int complearn_write_file(const char *fname, const GString *f)
{
g_assert(fname != NULL && strlen(fname) > 0);
FILE *fp = fopen(fname, "wb");
if (fp == NULL) {
g_error(_("Cannot open file %s for writing."), fname);
}
fwrite(f->str, 1, f->len, fp);
fclose(fp);
return 0;
}
GString *complearn_read_whole_file(const char *fname)
{
FILE *fp = fopen(fname, "rb");
if (fp == NULL)
g_error(_("Cannot open file %s for reading"), fname);
fseek(fp, 0, SEEK_END);
int sz = ftell(fp);
fseek(fp, 0, SEEK_SET);
char *b = calloc(sz, 1);
GString *result;
fread(b, 1, sz, fp);
fclose(fp);
result = g_string_new_len(b, sz);
g_free(b);
return result;
}
char *complearn_make_temp_dir(void)
{
char *result = complearn_make_temp_dir_name();
#ifdef __MINGW32__
mkdir(result);
#else
mkdir(result, 0700);
#endif
return result;
}
/* different each time */
char *complearn_make_temp_file_name(void)
{
char *tnam, *result;
static int i = 0;
char pidbuf[32];
sprintf(pidbuf, "%d-%d", ++i, getpid());
tnam = getenv("TMPDIR");
if (tnam == NULL)
tnam = "/tmp";
result = g_strconcat(tnam, "/clfile", pidbuf, NULL);
return result;
}
char *complearn_make_temp_dir_name(void)
{
int tid = 0;
#if OPENMP_ENABLED
if (!g_thread_supported ()) g_thread_init (NULL);
tid = omp_get_thread_num();
#endif
char *result = NULL, *tnam;
int incr = 0;
char pidbuf[64];
for (;;) {
sprintf(pidbuf, "%dx%dx%d", getpid(),incr,tid);
tnam = getenv("TMPDIR");
if (tnam == NULL)
tnam = "/tmp";
result = tnam;
result = g_strconcat(tnam, "/complearn-", pidbuf, NULL);
if (!g_file_test(result, G_FILE_TEST_EXISTS) && !g_file_test(result, G_FILE_TEST_IS_DIR))
break;
incr += 1;
}
return result;
}
char ** complearn_dupe_strings(const char * const * str)
{
int size = complearn_count_strings(str);
char **result;
int i;
result = calloc(size+1, sizeof(gpointer));
for (i = 0; i < size; i += 1)
result[i] = g_strdup(str[i]);
return result;
}
int complearn_count_strings(const char * const * str)
{
int acc = 0;
const char * const *cur = str;
while (cur && *cur) {
acc += 1;
cur += 1;
}
return acc;
}
CLArgumentEntry *complearn_new_arg(GString *block, const char *label) {
CLArgumentEntry *cl = calloc(1, sizeof(*cl));
cl->block = block;
cl->label = g_strdup(label);
return cl;
}
/* This function makes the off-diagonal elements symmetric by averaging. */
gsl_matrix *complearn_average_matrix(gsl_matrix *a)
{
int i,j;
gsl_matrix *res;
res = gsl_matrix_alloc(a->size1, a->size2);
for (i = 0;i<a->size1;i+=1)
for (j = 0; j <a->size2; j+=1) {
double v;
if (i == j)
gsl_matrix_set(res,i,j,gsl_matrix_get(a,i,j));
if (i <= j)
continue;
v = (gsl_matrix_get(a,i,j) + gsl_matrix_get(a,j,i))/2.0;
gsl_matrix_set(res,i,j,v);
gsl_matrix_set(res,j,i,v);
}
return res;
}
gsl_matrix *complearn_svd_project(gsl_matrix *a)
{
int retval;
gsl_matrix *res;
gsl_matrix *u, *v;
gsl_vector *s;
u = gsl_matrix_alloc(a->size1, a->size2);
gsl_matrix_memcpy(u, a);
v = gsl_matrix_alloc(a->size2, a->size2);
s = gsl_vector_alloc(a->size1);
retval = gsl_linalg_SV_decomp_jacobi(u, v, s);
// g_assert(retval == GSL_OK);
res = gsl_matrix_alloc(a->size1, a->size2);
gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, a, u, 0.0, res);
return res;
}
static gboolean is_last_common_char(char **inp, int which)
{
int i;
if (strlen(inp[0]) <= which)
return FALSE;
for (i = 1; inp[i]; i += 1)
if (strlen(inp[i]) <= which || inp[i][strlen(inp[i])-which-1] != inp[0][strlen(inp[0])-which-1])
return FALSE;
return TRUE;
}
static gboolean is_common_char(char **inp, int which)
{
int i;
if (strlen(inp[0]) <= which)
return FALSE;
for (i = 1; inp[i]; i += 1)
if (strlen(inp[i]) <= which || inp[i][which] != inp[0][which])
return FALSE;
return TRUE;
}
static char **chop_strings(char **inp, int prefixc, int suffixc)
{
int sc = complearn_count_strings((const char * const *) inp);
char **result = calloc(sc+1,sizeof(gpointer));
int i;
for (i = 0; i < sc; i += 1) {
char *p = inp[i]+prefixc;
char *res;
res = g_strdup(p);
if (suffixc && strlen(p) > suffixc)
res[strlen(res)-suffixc] = '\0';
result[i] = res;
}
return result;
}
char ** complearn_fix_labels(char **inp)
{
int prefixc = 0, suffixc = 0;
if (inp[1] != NULL) {
while (is_common_char(inp, prefixc))
prefixc += 1;
while ( is_last_common_char(inp, suffixc))
suffixc += 1;
}
return chop_strings(inp, prefixc, suffixc);
}
| {
"alphanum_fraction": 0.6691176471,
"avg_line_length": 25.9047619048,
"ext": "c",
"hexsha": "9936cd1cbfda3d8dee8a3e00b6a6511d2da4697c",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c70ac5ad7bcfe3af80a2a8f087ee6f5904820a66",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "rudi-cilibrasi/classic-complearn",
"max_forks_repo_path": "src/util.c",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "c70ac5ad7bcfe3af80a2a8f087ee6f5904820a66",
"max_issues_repo_issues_event_max_datetime": "2017-03-15T18:30:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-05-10T12:56:52.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "rudi-cilibrasi/classic-complearn",
"max_issues_repo_path": "src/util.c",
"max_line_length": 111,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "c70ac5ad7bcfe3af80a2a8f087ee6f5904820a66",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "rudi-cilibrasi/classic-complearn",
"max_stars_repo_path": "src/util.c",
"max_stars_repo_stars_event_max_datetime": "2018-06-08T11:13:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-14T13:52:31.000Z",
"num_tokens": 2877,
"size": 9792
} |
/* specfunc/bessel_Y1.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* 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.
*/
/* Author: G. Jungman */
#include <config.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_sf_trig.h>
#include <gsl/gsl_sf_bessel.h>
#include "error.h"
#include "bessel.h"
#include "bessel_amp_phase.h"
#include "cheb_eval.c"
/*-*-*-*-*-*-*-*-*-*-*-* Private Section *-*-*-*-*-*-*-*-*-*-*-*/
/* based on SLATEC besy1, 1977 version, w. fullerton */
/* chebyshev expansions
series for by1 on the interval 0. to 1.60000d+01
with weighted error 1.87e-18
log weighted error 17.73
significant figures required 17.83
decimal places required 18.30
*/
static double by1_data[14] = {
0.03208047100611908629,
1.262707897433500450,
0.00649996189992317500,
-0.08936164528860504117,
0.01325088122175709545,
-0.00089790591196483523,
0.00003647361487958306,
-0.00000100137438166600,
0.00000001994539657390,
-0.00000000030230656018,
0.00000000000360987815,
-0.00000000000003487488,
0.00000000000000027838,
-0.00000000000000000186
};
static cheb_series by1_cs = {
by1_data,
13,
-1, 1,
10
};
/*-*-*-*-*-*-*-*-*-*-*-* Functions with Error Codes *-*-*-*-*-*-*-*-*-*-*-*/
int gsl_sf_bessel_Y1_e(const double x, gsl_sf_result * result)
{
const double two_over_pi = 2.0/M_PI;
const double xmin = 1.571*GSL_DBL_MIN; /*exp ( amax1(alog(r1mach(1)), -alog(r1mach(2)))+.01) */
const double x_small = 2.0 * GSL_SQRT_DBL_EPSILON;
const double xmax = 1.0/GSL_DBL_EPSILON;
/* CHECK_POINTER(result) */
if(x <= 0.0) {
DOMAIN_ERROR(result);
}
else if(x < xmin) {
OVERFLOW_ERROR(result);
}
else if(x < x_small) {
const double lnterm = log(0.5*x);
gsl_sf_result J1;
gsl_sf_result c;
int status = gsl_sf_bessel_J1_e(x, &J1);
cheb_eval_e(&by1_cs, -1.0, &c);
result->val = two_over_pi * lnterm * J1.val + (0.5 + c.val)/x;
result->err = fabs(lnterm) * (fabs(GSL_DBL_EPSILON * J1.val) + J1.err) + c.err/x;
return status;
}
else if(x < 4.0) {
const double lnterm = log(0.5*x);
int status;
gsl_sf_result J1;
gsl_sf_result c;
cheb_eval_e(&by1_cs, 0.125*x*x-1.0, &c);
status = gsl_sf_bessel_J1_e(x, &J1);
result->val = two_over_pi * lnterm * J1.val + (0.5 + c.val)/x;
result->err = fabs(lnterm) * (fabs(GSL_DBL_EPSILON * J1.val) + J1.err) + c.err/x;
return status;
}
else if(x < xmax) {
const double z = 32.0/(x*x) - 1.0;
gsl_sf_result ca;
gsl_sf_result ct;
gsl_sf_result cp;
const int stat_ca = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bm1_cs, z, &ca);
const int stat_ct = cheb_eval_e(&_gsl_sf_bessel_amp_phase_bth1_cs, z, &ct);
const int stat_cp = gsl_sf_bessel_cos_pi4_e(x, ct.val/x, &cp);
const double sqrtx = sqrt(x);
const double ampl = (0.75 + ca.val) / sqrtx;
result->val = -ampl * cp.val;
result->err = fabs(cp.val) * ca.err/sqrtx + fabs(ampl) * cp.err;
result->err += GSL_DBL_EPSILON * fabs(result->val);
return GSL_ERROR_SELECT_3(stat_ca, stat_ct, stat_cp);
}
else {
UNDERFLOW_ERROR(result);
}
}
/*-*-*-*-*-*-*-*-*-* Functions w/ Natural Prototypes *-*-*-*-*-*-*-*-*-*-*/
#include "eval.h"
double gsl_sf_bessel_Y1(const double x)
{
EVAL_RESULT(gsl_sf_bessel_Y1_e(x, &result));
}
| {
"alphanum_fraction": 0.6380177161,
"avg_line_length": 30.268115942,
"ext": "c",
"hexsha": "205eed30533ac1bdef92c631c8b8a25acf826510",
"lang": "C",
"max_forks_count": 40,
"max_forks_repo_forks_event_max_datetime": "2022-03-03T23:23:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-26T15:31:16.000Z",
"max_forks_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "manggoguy/parsec-modified",
"max_forks_repo_path": "pkgs/libs/gsl/src/specfunc/bessel_Y1.c",
"max_issues_count": 12,
"max_issues_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_issues_repo_issues_event_max_datetime": "2022-03-13T03:54:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-12-15T08:30:19.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "manggoguy/parsec-modified",
"max_issues_repo_path": "pkgs/libs/gsl/src/specfunc/bessel_Y1.c",
"max_line_length": 97,
"max_stars_count": 64,
"max_stars_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "manggoguy/parsec-modified",
"max_stars_repo_path": "pkgs/libs/gsl/src/specfunc/bessel_Y1.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T13:26:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-06T00:30:56.000Z",
"num_tokens": 1373,
"size": 4177
} |
#ifndef _BCQL_H_
#define _BCQL_H_
#include <cblas.h>
#include <lapacke/lapacke.h>
#include <math.h>
//TODO Only one order is currently supported...
enum BCSK_Q_ORDER { BcskWXYZ = 130 };
enum BCSK_V_ORDER { BcskXYZ = 140 };
enum BCSK_M_ORDER { BcskColMajor = 102 }; //TODO Add Row Major
//copies first "len" entries of src to corresponding entries in dst
int dDub ( double *dst , double *src , unsigned int len ) ;
// Sets first "len" entries of array to 0;
int dZeros ( double *array , unsigned int len ) ;
// puts in dst the element-by-element sum of src1 and src2
int dSum2 ( double *dst , double alpha , double *src1 , double beta , double *src2 , unsigned int len ) ;
// sum up 3 arrays
int dSum3 ( double *dst ,
double a1 , double *src1 ,
double a2 , double *src2 ,
double a3 , double *src3 ,
unsigned int len ) ;
// sum up 4 arrays
int dSum4 ( double *dst ,
double a1 , double *src1 ,
double a2 , double *src2 ,
double a3 , double *src3 ,
double a4 , double *src4 ,
unsigned int len ) ;
// sum up 5 arrays
int dSum5 ( double *dst ,
double a1 , double *src1 ,
double a2 , double *src2 ,
double a3 , double *src3 ,
double a4 , double *src4 ,
double a5 , double *src5 ,
unsigned int len ) ;
// Compute cross product between 2 3D vecs
// c = a cross b ;
int dCross ( double *c , double *a , double *b ) ;
// Set the square matrix mat to the identity matrix
int dEye ( unsigned int order , double scale , double *mat ) ;
// Transpose square matrix
int dSqTr ( int n , double *src , double *dst ) ;
// Stores in quaternion c the hamilton product between quaternions a and b
int dHamilton (const enum BCSK_Q_ORDER Order , double *c , double *a , double *b ) ;
// Store in b the inverse of quaternion a
int dQInv( const enum BCSK_Q_ORDER Order , double *b , double *a) ;
//TODO vec arma_quat_between_vecs(const vec& a,const vec& b);
/***********************************************
* Compute angular velocity given the orientation quaternion
* and its derivative.
***********************************************/
//int dQuatInv( const enum LIBQUAT_ORDER BOrder , double *v , const enum LIBQUAT_ORDER AOrder , double *a) ;
int dQD2Vel ( const enum BCSK_V_ORDER v_order ,
const enum BCSK_Q_ORDER q_order ,
double *v ,
double *q ,
double *dqdt );
/*TODO**********************************************
* Compute angular accelleration given the orientation quaternion
* and its derivatives.
***********************************************/
/*vec arma_quat_d_to_acc(const vec& q0,const vec& q1,const vec& q2){
vec w1(4);
w1 = 2 * arma_quat_hamilton( q2-arma_quat_hamilton(arma_quat_hamilton(q1,arma_quat_inv(q0)),q1) , arma_quat_inv(q0) );
return(w1.subvec(1,3));
}
*/
/***********************************************
* Rotate vector v by rotation q.
* This formula should be faster than:
* v_new = q * v * q^-1
***********************************************/
//TODO vec arma_quat_rot ( const vec& q,const vec& v ) ;
/***********************************************
* Return matrix M from vector v s.t. for any x
* M*x = cross(v,x)
***********************************************/
int dCrossMat ( const enum BCSK_M_ORDER MOrder , double *M , const double *v ) ;
/***********************************************
* Applyes Rodriguez formula to convert quaternion q
* to rotation matrix R
***********************************************/
int dQ2R ( const enum BCSK_M_ORDER Order , const enum BCSK_Q_ORDER , double *R , double *q) ;
/***********************************************
* Conversion from rotation matrix R to quaternion q
***********************************************/
int dR2Q ( const enum BCSK_M_ORDER ROrder , const enum BCSK_Q_ORDER QOrder , double *R , double *q) ;
/* Saturate each elements of an array between -abs(sat_level) and +abs(sat_level)
*
* _______ _ +abs(sat_level)
* | /
* _______|/_______y _ 0
* /
* ______/| _ -abs(sat_level)
* x
*
* x: input value
* y: output value
*
* N.B.
*/
int dSat( double *src , double *dst , double sat_level , int len ) ;
// normalize vector X
int dNormalise ( const int N , double *X );
// compute rotation quaternion between v1 and v2
int dQbetVs ( double *Q , double *v1 , double *v2);
#endif
| {
"alphanum_fraction": 0.5475723928,
"avg_line_length": 32.5744680851,
"ext": "h",
"hexsha": "a4c25e78baa3a06583abb543139fc345ba6cfeb1",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4f4b15addba20f2cce04ab42ce97c68472f41340",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "fmr42/bcsk",
"max_forks_repo_path": "src/bcsk.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4f4b15addba20f2cce04ab42ce97c68472f41340",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "fmr42/bcsk",
"max_issues_repo_path": "src/bcsk.h",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4f4b15addba20f2cce04ab42ce97c68472f41340",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "fmr42/bcsk",
"max_stars_repo_path": "src/bcsk.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1157,
"size": 4593
} |
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <libiomp/omp.h>
#include <string.h>
#include <stdbool.h>
#ifdef __APPLE__
#include <cblas.h>
#define set_num_threads(x) openblas_set_num_threads(x)
#define get_num_threads() openblas_get_num_threads()
#else
#include <mkl.h>
#define set_num_threads(x) mkl_set_num_threads(x)
#define get_num_threads() mkl_get_num_threads()
#endif
int main(int argc, char **argv) {
char *filename = NULL;
int option = 0, omp_threads = 1;
while ((option = getopt(argc, argv, "f:t:")) != -1) {
switch (option) {
case 'f':
filename = optarg;
break;
case 't':
omp_threads = atoi(optarg);
break;
default:
printf("Usage: mpi_cg -f string -t num_threads \n");
return 0;
}
}
if (filename == NULL) {
printf("Usage: mpi_cg -f string -t num_threads \n");
return 0;
}
set_num_threads(omp_threads);
omp_set_num_threads(omp_threads);
int numTasks, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int qProcs = (int) sqrt(numTasks);
if (qProcs - sqrt(numTasks) != 0) {
if (rank == 0)
printf("np must be a square number\n");
MPI_Finalize();
return 0;
}
int n, dims[2] = {qProcs, qProcs}, periods[2] = {0, 0}, reorder = 0, coords[2], rc;
MPI_Comm cartComm;
MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, reorder, &cartComm);
MPI_Comm_rank(cartComm, &rank);
MPI_Cart_coords(cartComm, rank, 2, coords);
MPI_File matFile;
rc = MPI_File_open(cartComm, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &matFile);
if (rc && (rank == 0)) {
printf("Unable to open file %s\n", filename);
fflush(stdout);
}
MPI_Status status;
MPI_File_read(matFile, &n, 1, MPI_INT, &status);
int blockSize = (n + qProcs - 1) / qProcs; /* number of rows in _block_ */
int lastBlock = n - (qProcs - 1) * blockSize;
double *LocalA = (double *) malloc(blockSize * blockSize * sizeof(double));
MPI_Datatype readFileType;
MPI_Type_vector(blockSize, blockSize, n, MPI_DOUBLE, &readFileType);
MPI_Type_commit(&readFileType);
MPI_Offset offset = (MPI_Offset) (1 * sizeof(int) +
sizeof(double) * (blockSize * coords[1] + blockSize * n * coords[0]));
MPI_File_set_view(matFile, offset, MPI_DOUBLE, readFileType,
"native", MPI_INFO_NULL);
MPI_File_read_at(matFile, 0, LocalA, blockSize * blockSize, MPI_DOUBLE, &status);
MPI_Type_free(&readFileType);
if (coords[0] == qProcs - 1) {
memset(LocalA + lastBlock * blockSize, 0, (blockSize - lastBlock) * blockSize * sizeof(double));
}
if (coords[1] == qProcs - 1) {
int kk = 0;
for (kk = 0; kk < blockSize; ++kk) {
memset(LocalA + kk * blockSize + lastBlock, 0, (blockSize - lastBlock) * sizeof(double));
}
}
double *LocalB = (double *) malloc(blockSize * sizeof(double));
memset(LocalB, 0, blockSize * sizeof(double));
offset = (MPI_Offset) (1 * sizeof(int) + sizeof(double) * n * n);
MPI_File_set_view(matFile, offset, MPI_DOUBLE, MPI_DOUBLE,
"native", MPI_INFO_NULL);
offset = coords[1] * blockSize;
MPI_File_read_at_all(matFile, offset, LocalB, coords[1] == qProcs - 1 ? lastBlock : blockSize, MPI_DOUBLE, &status);
MPI_File_close(&matFile);
double mpi_start = MPI_Wtime();
MPI_Comm rowComm, colComm;
MPI_Comm_split(MPI_COMM_WORLD, coords[0], rank, &rowComm);
MPI_Comm_split(MPI_COMM_WORLD, coords[1], rank, &colComm);
double tolerance = 1e-8;
double alpha, beta, rho_new = 0.0, rho_old = 0.0;
int iteration = 0;
int world_root = numTasks - 1;
double *loc_Vr = (double *) malloc(blockSize * sizeof(double));
double *loc_Vp = (double *) malloc(blockSize * sizeof(double));
double *loc_Vw = (double *) malloc(blockSize * sizeof(double));
double *loc_Vx = (double *) malloc(blockSize * sizeof(double));
int row_rank, col_rank;
MPI_Comm_rank(colComm, &col_rank);
MPI_Comm_rank(rowComm, &row_rank);
//localr <- localB
memset(loc_Vx, 0, blockSize * sizeof(double));
cblas_dcopy(blockSize, LocalB, 1, loc_Vr, 1);
double b_norm2 = 0;
if (col_rank == qProcs - 1) {
double loc_b_dot = cblas_ddot((row_rank == qProcs - 1 ? lastBlock : blockSize), loc_Vr, 1, loc_Vr, 1);
MPI_Reduce(&loc_b_dot, &rho_new, 1, MPI_DOUBLE, MPI_SUM, qProcs - 1, rowComm);
b_norm2 = sqrt(rho_new);
}
int loopBreak = 0;
while (true) {
if (rank == world_root) {
loopBreak = (sqrt(rho_new) / b_norm2 < tolerance) ? 1 : 0;
}
MPI_Bcast(&loopBreak, 1, MPI_INT, world_root, MPI_COMM_WORLD);
if (loopBreak > 0)
break;
iteration++;
if (iteration == 1) {
cblas_dcopy(blockSize, loc_Vr, 1, loc_Vp, 1);
} else {
if (rank == world_root) {
beta = rho_new / rho_old;
}
MPI_Bcast(&beta, 1, MPI_DOUBLE, world_root, MPI_COMM_WORLD);
cblas_dscal((row_rank == qProcs - 1 ? lastBlock : blockSize), beta, loc_Vp, 1);
cblas_daxpy((row_rank == qProcs - 1 ? lastBlock : blockSize), 1.0, loc_Vr, 1, loc_Vp, 1);
}
cblas_dgemv(CblasRowMajor, CblasNoTrans, (col_rank == qProcs - 1 ? lastBlock : blockSize),
(row_rank == qProcs - 1 ? lastBlock : blockSize),
1.0, LocalA, blockSize, loc_Vp, 1, 0.0, loc_Vw, 1);
if (col_rank == row_rank) {
MPI_Reduce(MPI_IN_PLACE, loc_Vw, blockSize, MPI_DOUBLE, MPI_SUM, col_rank, rowComm);
} else {
MPI_Reduce(loc_Vw, loc_Vw, blockSize, MPI_DOUBLE, MPI_SUM, col_rank, rowComm);
}
MPI_Bcast(loc_Vw, (row_rank == qProcs - 1 ? lastBlock : blockSize), MPI_DOUBLE, row_rank, colComm);
if (col_rank == qProcs - 1) {
double loc_pw_dot = cblas_ddot((row_rank == qProcs - 1 ? lastBlock : blockSize), loc_Vp, 1, loc_Vw,
1), glo_pw_dot;
MPI_Reduce(&loc_pw_dot, &glo_pw_dot, 1, MPI_DOUBLE, MPI_SUM, qProcs - 1, rowComm);
if (rank == world_root) {
alpha = rho_new / glo_pw_dot;
}
}
MPI_Bcast(&alpha, 1, MPI_DOUBLE, world_root, MPI_COMM_WORLD);
cblas_daxpy((row_rank == qProcs - 1 ? lastBlock : blockSize), -alpha, loc_Vw, 1, loc_Vr, 1);
if (coords[0] == qProcs - 1) {
rho_old = rho_new;
cblas_daxpy((row_rank == qProcs - 1 ? lastBlock : blockSize), alpha, loc_Vp, 1, loc_Vx, 1);
double loc_r_dot = cblas_ddot(blockSize, loc_Vr, 1, loc_Vr, 1);
MPI_Reduce(&loc_r_dot, &rho_new, 1, MPI_DOUBLE, MPI_SUM, qProcs - 1, rowComm);
}
}
if (rank == world_root) {
printf("mpi_cg_it: %d\t", iteration);
printf("mpi_cg_time: %f\n", MPI_Wtime() - mpi_start);
}
MPI_Comm_free(&cartComm);
MPI_Comm_free(&colComm);
MPI_Comm_free(&rowComm);
if (col_rank == qProcs - 1) {
for (rc = 0; rc < (row_rank == qProcs - 1 ? lastBlock : blockSize); ++rc) {
if (fabs(loc_Vx[rc] - 1) > 1e-3) {
printf("MPI_CG_ERR %f \n", loc_Vx[rc]);
break;
}
}
}
MPI_Finalize();
}
| {
"alphanum_fraction": 0.5872536137,
"avg_line_length": 36.0663507109,
"ext": "c",
"hexsha": "33e50246d91f6dd81a7ebcb05ea7e30040f051fc",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d2fe69b49a6c13ccfb8404bce3d161cf0043d599",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "baishuai/MEXP",
"max_forks_repo_path": "mpi/mpi_cg.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d2fe69b49a6c13ccfb8404bce3d161cf0043d599",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "baishuai/MEXP",
"max_issues_repo_path": "mpi/mpi_cg.c",
"max_line_length": 120,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d2fe69b49a6c13ccfb8404bce3d161cf0043d599",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "baishuai/MEXP",
"max_stars_repo_path": "mpi/mpi_cg.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2215,
"size": 7610
} |
#pragma once
#include <halley/maths/vector2.h>
#include <halley/text/halleystring.h>
#include <gsl/gsl>
namespace Halley
{
class FontFacePimpl;
class Image;
struct FontMetrics
{
Vector2f advance;
Vector2f bearingHorizontal;
Vector2f bearingVertical;
};
struct KerningPair
{
int left;
int right;
Vector2f kerning;
KerningPair(int left, int right, Vector2f kerning) : left(left), right(right), kerning(kerning) {}
};
class FontFace
{
public:
explicit FontFace(String filename);
explicit FontFace(gsl::span<const gsl::byte> data);
~FontFace();
void setSize(float size);
String getName() const;
float getSize() const;
float getHeight() const;
float getAscender() const;
Vector<int> getCharCodes() const;
Vector2i getGlyphSize(int charCode) const;
void drawGlyph(Image& image, int charcode, Vector2i pos) const;
FontMetrics getMetrics(int charcode, float scale = 1.0f) const;
Vector<KerningPair> getKerning(const Vector<int>& codes) const;
private:
std::unique_ptr<FontFacePimpl> pimpl;
float size = 0;
};
}
| {
"alphanum_fraction": 0.7220149254,
"avg_line_length": 20.2264150943,
"ext": "h",
"hexsha": "28a544e7d25631ad9b9f2521a682c93ebff8092f",
"lang": "C",
"max_forks_count": 193,
"max_forks_repo_forks_event_max_datetime": "2022-03-22T12:59:58.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-10-23T06:08:41.000Z",
"max_forks_repo_head_hexsha": "fc4f153956cc34d7fa02b76850e22183b8e30e25",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "sunhay/halley",
"max_forks_repo_path": "src/tools/tools/include/halley/tools/make_font/font_face.h",
"max_issues_count": 53,
"max_issues_repo_head_hexsha": "fc4f153956cc34d7fa02b76850e22183b8e30e25",
"max_issues_repo_issues_event_max_datetime": "2022-01-10T13:52:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-09T16:25:04.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "sunhay/halley",
"max_issues_repo_path": "src/tools/tools/include/halley/tools/make_font/font_face.h",
"max_line_length": 100,
"max_stars_count": 3262,
"max_stars_repo_head_hexsha": "fc4f153956cc34d7fa02b76850e22183b8e30e25",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "sunhay/halley",
"max_stars_repo_path": "src/tools/tools/include/halley/tools/make_font/font_face.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-31T17:47:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-10T15:24:10.000Z",
"num_tokens": 304,
"size": 1072
} |
/*
COPYRIGHT DISCLAIMER
Vincent Le Guilloux, Peter Schmidtke and Pierre Tuffery, hereby
disclaim all copyright interest in the program “fpocket” (which
performs protein cavity detection) written by Vincent Le Guilloux and Peter
Schmidtke.
Vincent Le Guilloux 28 November 2008
Peter Schmidtke 28 November 2008
Pierre Tuffery 28 November 2008
GNU GPL
This file is part of the fpocket package.
fpocket 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 3 of the License, or
(at your option) any later version.
fpocket 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 fpocket. If not, see <http://www.gnu.org/licenses/>.
**/
#ifndef DH_UTILS
#define DH_UTILS
/* ------------------------------ INCLUDES ---------------------------------- */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <time.h>
#ifdef MD_USE_GSL /* GSL */
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#endif /* /GSL */
#include "memhandler.h"
/* ------------------------------- PUBLIC MACROS ---------------------------- */
#define M_MAX_PDB_NAME_LEN 200 /**< maximum pdb filename length*/
#define M_SIGN 1
#define M_NO_SIGN 0
#ifdef MD_USE_GSL /* GSL */
#define M_GEN_MTWISTER gsl_rng_mt19937
#define M_GEN_GFSR4 gsl_rng_gfsr4
#define M_GEN_TAUS gsl_rng_taus2
#define M_GEN_RANLXS0 gsl_rng_ranlxs0
#define M_GEN_RANLXS1 gsl_rng_ranlxs1
#endif /* /GSL */
/* ------------------------------ PUBLIC STRUCTURES ------------------------- */
typedef struct tab_str
{
char **t_str ;
int nb_str ;
} tab_str ;
/* ------------------------------- PROTOTYPES ------------------------------- */
int str_is_number(const char *str, const int sign) ;
int str_is_float(const char *str, const int sign) ;
void str_trim(char *str) ;
tab_str* str_split(const char *str, const int sep) ;
tab_str* f_readl(const char *fpath, int nchar_max) ;
void free_tab_str(tab_str *tstr) ;
void print_tab_str(tab_str* strings) ;
int in_tab(int *tab, int size, int val) ;
int index_of(int *tab, int size, int val) ;
void remove_ext(char *str) ;
void remove_path(char *str) ;
void extract_ext(char *str, char *dest) ;
void extract_path(char *str, char *dest) ;
void start_rand_generator(void) ;
float rand_uniform(float min, float max) ;
FILE* fopen_pdb_check_case(char *name, const char *mode) ;
float float_get_min_in_2D_array(float **t,size_t n,int col);
float float_get_max_in_2D_array(float **t,size_t n,int col);
#endif
| {
"alphanum_fraction": 0.6676849966,
"avg_line_length": 26.3035714286,
"ext": "h",
"hexsha": "03c1dc4b67047508777d429d9b9b74ea4edcdcb8",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "29d93d38a9757d0a10d83c0385cd028a6ae39fd4",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "hjuinj/docker_fpocket",
"max_forks_repo_path": "fpocket2/headers/utils.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "29d93d38a9757d0a10d83c0385cd028a6ae39fd4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "hjuinj/docker_fpocket",
"max_issues_repo_path": "fpocket2/headers/utils.h",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "29d93d38a9757d0a10d83c0385cd028a6ae39fd4",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "hjuinj/docker_fpocket",
"max_stars_repo_path": "fpocket2/headers/utils.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 739,
"size": 2946
} |
/// \file angles.c
/// \brief Optimize polar angles with respect to Coulomb repulsion, given the radii.
//
// Copyright (c) 2014, Christian B. Mendl
// All rights reserved.
// http://christian.mendl.net
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Simplified BSD License
// http://www.opensource.org/licenses/bsd-license.php
//
// Reference:
// Christian B. Mendl, Francesc Malet, Paola Gori-Giorgi
// Wigner localization in quantum dots from Kohn-Sham density functional theory without symmetry breaking
// Physical Review B 89, 125106 (2014)
// (preprint http://arxiv.org/abs/1311.6011)
//_______________________________________________________________________________________________________________________
//
#include "angles.h"
#include "coulomb.h"
#include "util.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdlib.h>
#include <memory.h>
#include <float.h>
#include <assert.h>
#include <stdio.h>
// LAPACK functions
#include <acml.h>
// GSL library
#include <gsl/gsl_multimin.h>
#include <gsl/gsl_siman.h>
static const int maxiter = 64; //!< maximum number of iterations for local angle optimization
static const double step_size = 0.01; //!< step size for angle optimization
//_______________________________________________________________________________________________________________________
//
// GSL wrappers of Vee() for local minimization
/// \brief GSL parameters for angle optimization
typedef struct
{
double phi0;
const double *r;
}
gsl_angle_params_t;
/// \brief GSL wrapper for Vee()
static double gslVee(const gsl_vector *phiRest, void *p)
{
int i;
const gsl_angle_params_t *params = (gsl_angle_params_t *)p;
double v_val;
// first angle is held fixed
const int nelec = (int)phiRest->size + 1;
double *phi = (double *)malloc(nelec*sizeof(double));
phi[0] = params->phi0;
for (i = 1; i < nelec; i++) {
phi[i] = gsl_vector_get(phiRest, i-1);
}
v_val = Vee(nelec, params->r, phi);
free(phi);
return v_val;
}
/// \brief GSL wrapper for VeeGradPhi()
static void gslVeeGradPhi(const gsl_vector *phiRest, void *p, gsl_vector *df)
{
int i;
const gsl_angle_params_t *params = (gsl_angle_params_t *)p;
double *grad;
// first angle is held fixed
const int nelec = (int)phiRest->size + 1;
double *phi = (double *)malloc(nelec*sizeof(double));
phi[0] = params->phi0;
for (i = 1; i < nelec; i++) {
phi[i] = gsl_vector_get(phiRest, i-1);
}
grad = (double *)malloc(nelec*sizeof(double));
// calculate gradient
VeeGradPhi(nelec, params->r, phi, grad);
// ignore derivative with respect to first angle (held fixed)
for (i = 1; i < nelec; i++) {
gsl_vector_set(df, i-1, grad[i]);
}
free(grad);
free(phi);
}
/// \brief GSL wrapper for both 'Vee()' and 'VeeGradPhi()' together
static void gslVeeValGradPhi(const gsl_vector *phiRest, void *p, double *f, gsl_vector *df)
{
int i;
const gsl_angle_params_t *params = (gsl_angle_params_t *)p;
double *phi;
double *grad;
// first angle is held fixed
const int nelec = (int)phiRest->size + 1;
phi = (double *)malloc(nelec*sizeof(double));
phi[0] = params->phi0;
for (i = 1; i < nelec; i++) {
phi[i] = gsl_vector_get(phiRest, i-1);
}
*f = Vee(nelec, params->r, phi);
grad = (double *)malloc(nelec*sizeof(double));
// calculate gradient
VeeGradPhi(nelec, params->r, phi, grad);
// ignore derivative with respect to first angle (which is held fixed)
for (i = 1; i < nelec; i++) {
gsl_vector_set(df, i-1, grad[i]);
}
free(grad);
free(phi);
}
//_______________________________________________________________________________________________________________________
///
/// \brief Optimize polar angles with respect to Coulomb repulsion, given the radii
///
/// \param nelec number of electrons
/// \param r radii, array of length 'nelec'
/// \param phi serves as input (starting values) and output (optimized angles); array of length 'nelec';
/// phi[0] is not changed due to invariance under global rotation
///
/// \return detailed error description, if any
///
error_desc_t OptimizeAngles(const int nelec, const double *r, double *phi)
{
int i, j, k;
error_desc_t err = { 0 };
int status;
// tolerance for convergence test based on gradient
const double tol = nelec < 7 ? 1e-12 : 1e-10;
const gsl_multimin_fdfminimizer_type *T = gsl_multimin_fdfminimizer_vector_bfgs2; // alternative: gsl_multimin_fdfminimizer_conjugate_fr
gsl_multimin_fdfminimizer *s = gsl_multimin_fdfminimizer_alloc(T, nelec-1);
gsl_angle_params_t params;
params.phi0 = phi[0];
params.r = r;
gsl_multimin_function_fdf my_func;
my_func.n = nelec-1;
my_func.f = gslVee;
my_func.df = gslVeeGradPhi;
my_func.fdf = gslVeeValGradPhi;
my_func.params = ¶ms;
// starting point
// omit first angle phi[0]
gsl_vector *x = gsl_vector_alloc(nelec-1);
for (i = 1; i < nelec; i++) {
gsl_vector_set(x, i-1, phi[i]);
}
gsl_multimin_fdfminimizer_set(s, &my_func, x, step_size, 0.1);
for (k = 0; k < maxiter; k++)
{
status = gsl_multimin_fdfminimizer_iterate(s);
// interval [-pi, pi]
for (i = 0; i < nelec-1; i++)
{
double curphi = gsl_vector_get(s->x, i);
assert(!isinf(curphi));
if (curphi < -M_PI) // using "if" instead of "while" to avoid infinite loop if curphi is +-1.#INF
{
curphi += 2*M_PI;
}
else if (curphi > M_PI)
{
curphi -= 2*M_PI;
}
gsl_vector_set(s->x, i, curphi);
}
// check status
if (status != 0) {
err.codes |= E_ITERATION;
err.msg = gsl_strerror(status);
fprintf(stderr, "Warning: 'gsl_multimin_fdfminimizer_iterate' failed at iteration %i, error: %s.\n", k, err.msg);
break;
}
// convergence test
status = gsl_multimin_test_gradient(s->gradient, tol);
if (status == GSL_SUCCESS) {
printf("'gsl_multimin_test_gradient()' successful.\n");
break;
}
}
// norm of gradient
double delta = 0;
for (i = 0; i < nelec-1; i++)
{
delta += square(gsl_vector_get(s->gradient, i));
}
// 2-norm
delta = sqrt(delta);
printf("final delta: %g\n", delta);
if (k == maxiter)
{
fprintf(stderr, "Warning: 'OptimizeAngles' did not converge within %i iterations, final delta: %g.\n", maxiter, delta);
err.codes |= E_CONVERGENCE;
err.conv_delta = delta;
}
// copy values back
for (i = 1; i < nelec; i++) {
phi[i] = gsl_vector_get(s->x, i-1);
}
gsl_multimin_fdfminimizer_free(s);
gsl_vector_free(x);
// consistency check: all eigenvalues of Hessian matrix should be non-negative
{
double *hessfull = (double *)malloc(nelec*nelec*sizeof(double));
double *hesssubm = (double *)malloc((nelec-1)*(nelec-1)*sizeof(double));
double *eigenval = (double *)malloc((nelec-1)*sizeof(double));
// calculate Hessian matrix
VeeHessPhi(nelec, r, phi, hessfull);
// omit first row and column in Hessian matrix since phi[0] is fixed
for (j = 1; j < nelec; j++)
{
for (i = 1; i < nelec; i++)
{
hesssubm[(i-1)+(j-1)*(nelec-1)] = hessfull[i+j*nelec];
}
}
// calculate eigenvalues
dsyev('N', 'U', nelec-1, hesssubm, nelec-1, eigenval, &status);
// check for errors
if (status != 0) {
fprintf(stderr, "Warning: 'dsyev' failed, info: %i\n", status);
err.codes |= E_LAPACK;
}
if (eigenval[0] < 0) {
fprintf(stderr, "Warning: Hessian has negative eigenvalue %g.\n", eigenval[0]);
err.codes |= E_NEG_HESS;
err.hess_eig = eigenval[0];
}
free(eigenval);
free(hesssubm);
free(hessfull);
}
return err;
}
//_______________________________________________________________________________________________________________________
///
/// \brief Perform a global optimization of the polar angles with respect to Coulomb repulsion, given the radii
///
/// \param nelec number of electrons
/// \param r radii, array of length 'nelec'
/// \param phi serves as input (starting values) and output (optimized angles); array of length 'nelec';
/// phi[0] is not changed due to invariance under global rotation
/// \param optVee optimized Coulomb repulsion (output)
/// \return detailed error description, if any
///
error_desc_t OptimizeAnglesGlobal(const int nelec, const double *r, double *phi, double *optVee)
{
int i, k, l;
error_desc_t err = OptimizeAngles(nelec, r, phi);
// temporary storage for angles
double *chi = (double *)malloc(nelec*sizeof(double));
// try permuting angles to find minimum value
(*optVee) = Vee(nelec, r, phi);
for (i = 0; i < 32; i++) // iterate several times
{
// for all pairs of electrons...
for (l = 1; l < nelec; l++) // angle of first electron always zero
{
for (k = 1; k < l; k++)
{
double curV;
memcpy(chi, phi, nelec*sizeof(double));
// permute k <-> l
chi[k] = phi[l];
chi[l] = phi[k];
error_desc_t cur_err = OptimizeAngles(nelec, r, chi);
curV = Vee(nelec, r, chi);
if (curV < (*optVee))
{
// only accumulate error if we really use the optimized angles
AccumulateError(&err, &cur_err);
// save values
memcpy(phi, chi, nelec*sizeof(double));
(*optVee) = curV;
}
}
}
}
// clean up
free(chi);
return err;
}
/*
//_______________________________________________________________________________________________________________________
//
// GSL wrappers of Vee() for global minimization by simulated annealing
typedef struct
{
int nelec;
const double *r;
double phi[10];
}
saConfig_t;
static double saVee(void *xp)
{
const saConfig_t *x = (saConfig_t *)xp;
return Vee(x->nelec, x->r, x->phi);
}
static void saStep(const gsl_rng *randgen, void *xp, double step_size)
{
int i;
saConfig_t *x = (saConfig_t *)xp;
// first angle always fixed
for (i = 1; i < x->nelec; i++)
{
double u = gsl_rng_uniform(randgen);
x->phi[i] += step_size * (u - 0.5); // divide by nelec ?
// [-pi,pi] range
if (x->phi[i] < -M_PI)
{
x->phi[i] += 2*M_PI;
}
else if (x->phi[i] > M_PI)
{
x->phi[i] -= 2*M_PI;
}
}
}
static double saDistance(void *xp, void *yp)
{
int i;
const saConfig_t *x = (saConfig_t *)xp;
const saConfig_t *y = (saConfig_t *)yp;
// distance between angles
double dphi[10];
for (i = 0; i < x->nelec; i++)
{
dphi[i] = x->phi[i] - y->phi[i];
// [-pi,pi] range
if (dphi[i] < -M_PI)
{
dphi[i] += 2*M_PI;
}
else if (dphi[i] > M_PI)
{
dphi[i] -= 2*M_PI;
}
}
assert(x->nelec == y->nelec);
return Norm(dphi + 1, x->nelec - 1); // skip first angle (always held fixed)
}
static void saPrint(void *xp)
{
int i;
const saConfig_t *x = (saConfig_t *)xp;
printf(" angles phi: ");
for (i = 0; i < x->nelec; i++) {
printf("%f ", x->phi[i]);
}
}
//_______________________________________________________________________________________________________________________
///
/// \brief Globally optimize polar angles with respect to Coulomb repulsion, given the radii
///
/// \param nelec number of electrons
/// \param r radii, array of length 'nelec'
/// \param phi serves as input (starting values) and output (optimized angles); array of length 'nelec';
/// phi[0] is not changed due to invariance under global rotation
///
/// \return detailed error description, if any
///
error_desc_t OptimizeAnglesGlobal(const int nelec, const double *r, double *phi)
{
const gsl_rng_type *T;
gsl_rng *randgen;
gsl_siman_params_t params;
error_desc_t err = { 0 };
// initial configuration
saConfig_t config;
config.nelec = nelec;
config.r = r;
memcpy(config.phi, phi, nelec*sizeof(double));
gsl_rng_env_setup();
// random number generator
T = gsl_rng_default;
randgen = gsl_rng_alloc(T);
// parameters
params.n_tries = 200; // how many points do we try before stepping
params.iters_fixed_T = 1000; // how many iterations for each T?
params.step_size = 0.01 * M_PI; // max step size in random walk
params.k = 1.0; // virtual Boltzmann constant
params.t_initial = 0.001; // initial temperature
params.mu_t = 1.004; // damping factor for temperature
params.t_min = 2.0e-7; // minimum temperature
gsl_siman_solve(randgen, &config, saVee, saStep, saDistance, saPrint, NULL, NULL, NULL, sizeof(saConfig_t), params);
// first angle must not change
assert(config.phi[0] == phi[0]);
// store optimized angles in 'phi'
memcpy(phi, config.phi, nelec*sizeof(double));
// clean up
gsl_rng_free(randgen);
// consistency check: all eigenvalues of Hessian matrix should be non-negative
{
int i, j;
int status;
double *hessfull = (double *)malloc(nelec*nelec*sizeof(double));
double *hesssubm = (double *)malloc((nelec-1)*(nelec-1)*sizeof(double));
double *eigenval = (double *)malloc((nelec-1)*sizeof(double));
// calculate Hessian matrix
VeeHessPhi(nelec, r, phi, hessfull);
// omit first row and column in Hessian matrix since phi[0] is fixed
for (j = 1; j < nelec; j++)
{
for (i = 1; i < nelec; i++)
{
hesssubm[(i-1)+(j-1)*(nelec-1)] = hessfull[i+j*nelec];
}
}
// calculate eigenvalues
dsyev('N', 'U', nelec-1, hesssubm, nelec-1, eigenval, &status);
// check for errors
if (status != 0) {
fprintf(stderr, "Warning: 'dsyev' failed, info: %i\n", status);
err.codes |= E_LAPACK;
}
if (eigenval[0] < 0) {
fprintf(stderr, "Warning: Hessian has negative eigenvalue %g.\n", eigenval[0]);
err.codes |= E_NEG_HESS;
err.hess_eig = eigenval[0];
}
free(eigenval);
free(hesssubm);
free(hessfull);
}
return err;
}
*/ | {
"alphanum_fraction": 0.6726825267,
"avg_line_length": 25.5896946565,
"ext": "c",
"hexsha": "d7550bc1251ce5a95a9198891d1d60c017c6f89d",
"lang": "C",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-03-25T22:00:35.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-26T21:06:00.000Z",
"max_forks_repo_head_hexsha": "f149e1d6684ea321b62710638f153d3dce196ca2",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Arfaouim/quantum-dot",
"max_forks_repo_path": "src/angles.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f149e1d6684ea321b62710638f153d3dce196ca2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "Arfaouim/quantum-dot",
"max_issues_repo_path": "src/angles.c",
"max_line_length": 137,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f149e1d6684ea321b62710638f153d3dce196ca2",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "Arfaouim/quantum-dot",
"max_stars_repo_path": "src/angles.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-24T13:59:40.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-24T13:59:40.000Z",
"num_tokens": 4098,
"size": 13409
} |
#pragma once
#include <gsl/span>
#include "halley/core/api/audio_api.h"
#include "audio_buffer.h"
namespace Halley
{
class AudioMixer
{
public:
static void mixAudio(AudioSamplesConst src, AudioSamples dst, float gainStart, float gainEnd);
static void mixAudio(AudioMultiChannelSamplesConst src, AudioMultiChannelSamples dst, float gainStart, float gainEnd);
static void mixAudio(AudioMultiChannelSamples src, AudioMultiChannelSamples dst, float gainStart, float gainEnd);
static void interleaveChannels(AudioSamples dst, gsl::span<AudioBuffer*> srcs);
static void concatenateChannels(AudioSamples dst, gsl::span<AudioBuffer*> srcs);
static void compressRange(AudioSamples buffer);
static void zero(AudioSamples dst);
static void zero(AudioMultiChannelSamples dst, size_t nChannels = 8);
static void zeroRange(AudioMultiChannelSamples dst, size_t nChannels, size_t start, size_t len = std::numeric_limits<size_t>::max());
static void copy(AudioMultiChannelSamples dst, AudioMultiChannelSamples src, size_t nChannels = 8);
static void copy(AudioSamples dst, AudioSamples src);
static void copy(AudioSamples dst, AudioSamples src, float gainStart, float gainEnd);
};
}
| {
"alphanum_fraction": 0.7961570593,
"avg_line_length": 44.3333333333,
"ext": "h",
"hexsha": "d655e55ba5629a929f03d5c8065f05286ef274dd",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5f6a5dd7d44b9c12d2c124436969ff2dfa69e3f4",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "amrezzd/halley",
"max_forks_repo_path": "src/engine/audio/src/audio_mixer.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5f6a5dd7d44b9c12d2c124436969ff2dfa69e3f4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "amrezzd/halley",
"max_issues_repo_path": "src/engine/audio/src/audio_mixer.h",
"max_line_length": 135,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5f6a5dd7d44b9c12d2c124436969ff2dfa69e3f4",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "amrezzd/halley",
"max_stars_repo_path": "src/engine/audio/src/audio_mixer.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 276,
"size": 1197
} |
/* blas/gsl_cblas.h
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* 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.
*/
/* This is a copy of the CBLAS standard header.
* We carry this around so we do not have to
* break our model for flexible BLAS functionality.
*/
#ifndef __GSL_CBLAS_H__
#define __GSL_CBLAS_H__
#include <stddef.h>
#include <gsl/gsl_types.h>
#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
#else
#define __BEGIN_DECLS /* empty */
#define __END_DECLS /* empty */
#endif
__BEGIN_DECLS
/*
* Enumerated and derived types
*/
#define CBLAS_INDEX size_t /* this may vary between platforms */
enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102};
enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113};
enum CBLAS_UPLO {CblasUpper=121, CblasLower=122};
enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132};
enum CBLAS_SIDE {CblasLeft=141, CblasRight=142};
/*
* ===========================================================================
* Prototypes for level 1 BLAS functions (complex are recast as routines)
* ===========================================================================
*/
GSL_EXPORT float cblas_sdsdot(const int N, const float alpha, const float *X,
const int incX, const float *Y, const int incY);
GSL_EXPORT double cblas_dsdot(const int N, const float *X, const int incX, const float *Y,
const int incY);
GSL_EXPORT float cblas_sdot(const int N, const float *X, const int incX,
const float *Y, const int incY);
GSL_EXPORT double cblas_ddot(const int N, const double *X, const int incX,
const double *Y, const int incY);
/*
* Functions having prefixes Z and C only
*/
GSL_EXPORT void cblas_cdotu_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotu);
GSL_EXPORT void cblas_cdotc_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotc);
GSL_EXPORT void cblas_zdotu_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotu);
GSL_EXPORT void cblas_zdotc_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotc);
/*
* Functions having prefixes S D SC DZ
*/
GSL_EXPORT float cblas_snrm2(const int N, const float *X, const int incX);
GSL_EXPORT float cblas_sasum(const int N, const float *X, const int incX);
GSL_EXPORT double cblas_dnrm2(const int N, const double *X, const int incX);
GSL_EXPORT double cblas_dasum(const int N, const double *X, const int incX);
GSL_EXPORT float cblas_scnrm2(const int N, const void *X, const int incX);
GSL_EXPORT float cblas_scasum(const int N, const void *X, const int incX);
GSL_EXPORT double cblas_dznrm2(const int N, const void *X, const int incX);
GSL_EXPORT double cblas_dzasum(const int N, const void *X, const int incX);
/*
* Functions having standard 4 prefixes (S D C Z)
*/
GSL_EXPORT CBLAS_INDEX cblas_isamax(const int N, const float *X, const int incX);
GSL_EXPORT CBLAS_INDEX cblas_idamax(const int N, const double *X, const int incX);
GSL_EXPORT CBLAS_INDEX cblas_icamax(const int N, const void *X, const int incX);
GSL_EXPORT CBLAS_INDEX cblas_izamax(const int N, const void *X, const int incX);
/*
* ===========================================================================
* Prototypes for level 1 BLAS routines
* ===========================================================================
*/
/*
* Routines with standard 4 prefixes (s, d, c, z)
*/
GSL_EXPORT void cblas_sswap(const int N, float *X, const int incX,
float *Y, const int incY);
GSL_EXPORT void cblas_scopy(const int N, const float *X, const int incX,
float *Y, const int incY);
GSL_EXPORT void cblas_saxpy(const int N, const float alpha, const float *X,
const int incX, float *Y, const int incY);
GSL_EXPORT void cblas_dswap(const int N, double *X, const int incX,
double *Y, const int incY);
GSL_EXPORT void cblas_dcopy(const int N, const double *X, const int incX,
double *Y, const int incY);
GSL_EXPORT void cblas_daxpy(const int N, const double alpha, const double *X,
const int incX, double *Y, const int incY);
GSL_EXPORT void cblas_cswap(const int N, void *X, const int incX,
void *Y, const int incY);
GSL_EXPORT void cblas_ccopy(const int N, const void *X, const int incX,
void *Y, const int incY);
GSL_EXPORT void cblas_caxpy(const int N, const void *alpha, const void *X,
const int incX, void *Y, const int incY);
GSL_EXPORT void cblas_zswap(const int N, void *X, const int incX,
void *Y, const int incY);
GSL_EXPORT void cblas_zcopy(const int N, const void *X, const int incX,
void *Y, const int incY);
GSL_EXPORT void cblas_zaxpy(const int N, const void *alpha, const void *X,
const int incX, void *Y, const int incY);
/*
* Routines with S and D prefix only
*/
GSL_EXPORT void cblas_srotg(float *a, float *b, float *c, float *s);
GSL_EXPORT void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
GSL_EXPORT void cblas_srot(const int N, float *X, const int incX,
float *Y, const int incY, const float c, const float s);
GSL_EXPORT void cblas_srotm(const int N, float *X, const int incX,
float *Y, const int incY, const float *P);
GSL_EXPORT void cblas_drotg(double *a, double *b, double *c, double *s);
GSL_EXPORT void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
GSL_EXPORT void cblas_drot(const int N, double *X, const int incX,
double *Y, const int incY, const double c, const double s);
GSL_EXPORT void cblas_drotm(const int N, double *X, const int incX,
double *Y, const int incY, const double *P);
/*
* Routines with S D C Z CS and ZD prefixes
*/
GSL_EXPORT void cblas_sscal(const int N, const float alpha, float *X, const int incX);
GSL_EXPORT void cblas_dscal(const int N, const double alpha, double *X, const int incX);
GSL_EXPORT void cblas_cscal(const int N, const void *alpha, void *X, const int incX);
GSL_EXPORT void cblas_zscal(const int N, const void *alpha, void *X, const int incX);
GSL_EXPORT void cblas_csscal(const int N, const float alpha, void *X, const int incX);
GSL_EXPORT void cblas_zdscal(const int N, const double alpha, void *X, const int incX);
/*
* ===========================================================================
* Prototypes for level 2 BLAS
* ===========================================================================
*/
/*
* Routines with standard 4 prefixes (S, D, C, Z)
*/
GSL_EXPORT void cblas_sgemv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const float alpha, const float *A, const int lda,
const float *X, const int incX, const float beta,
float *Y, const int incY);
GSL_EXPORT void cblas_sgbmv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const float alpha,
const float *A, const int lda, const float *X,
const int incX, const float beta, float *Y, const int incY);
GSL_EXPORT void cblas_strmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *A, const int lda,
float *X, const int incX);
GSL_EXPORT void cblas_stbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const float *A, const int lda,
float *X, const int incX);
GSL_EXPORT void cblas_stpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *Ap, float *X, const int incX);
GSL_EXPORT void cblas_strsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *A, const int lda, float *X,
const int incX);
GSL_EXPORT void cblas_stbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const float *A, const int lda,
float *X, const int incX);
GSL_EXPORT void cblas_stpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *Ap, float *X, const int incX);
GSL_EXPORT void cblas_dgemv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const double alpha, const double *A, const int lda,
const double *X, const int incX, const double beta,
double *Y, const int incY);
GSL_EXPORT void cblas_dgbmv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const double alpha,
const double *A, const int lda, const double *X,
const int incX, const double beta, double *Y, const int incY);
GSL_EXPORT void cblas_dtrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *A, const int lda,
double *X, const int incX);
GSL_EXPORT void cblas_dtbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const double *A, const int lda,
double *X, const int incX);
GSL_EXPORT void cblas_dtpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *Ap, double *X, const int incX);
GSL_EXPORT void cblas_dtrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *A, const int lda, double *X,
const int incX);
GSL_EXPORT void cblas_dtbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const double *A, const int lda,
double *X, const int incX);
GSL_EXPORT void cblas_dtpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *Ap, double *X, const int incX);
GSL_EXPORT void cblas_cgemv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *X, const int incX, const void *beta,
void *Y, const int incY);
GSL_EXPORT void cblas_cgbmv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const void *alpha,
const void *A, const int lda, const void *X,
const int incX, const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_ctrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda,
void *X, const int incX);
GSL_EXPORT void cblas_ctbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
GSL_EXPORT void cblas_ctpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
GSL_EXPORT void cblas_ctrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda, void *X,
const int incX);
GSL_EXPORT void cblas_ctbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
GSL_EXPORT void cblas_ctpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
GSL_EXPORT void cblas_zgemv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *X, const int incX, const void *beta,
void *Y, const int incY);
GSL_EXPORT void cblas_zgbmv(const enum CBLAS_ORDER order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const void *alpha,
const void *A, const int lda, const void *X,
const int incX, const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_ztrmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda,
void *X, const int incX);
GSL_EXPORT void cblas_ztbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
GSL_EXPORT void cblas_ztpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
GSL_EXPORT void cblas_ztrsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda, void *X,
const int incX);
GSL_EXPORT void cblas_ztbsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
GSL_EXPORT void cblas_ztpsv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
/*
* Routines with S and D prefixes only
*/
GSL_EXPORT void cblas_ssymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *A,
const int lda, const float *X, const int incX,
const float beta, float *Y, const int incY);
GSL_EXPORT void cblas_ssbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const float alpha, const float *A,
const int lda, const float *X, const int incX,
const float beta, float *Y, const int incY);
GSL_EXPORT void cblas_sspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *Ap,
const float *X, const int incX,
const float beta, float *Y, const int incY);
GSL_EXPORT void cblas_sger(const enum CBLAS_ORDER order, const int M, const int N,
const float alpha, const float *X, const int incX,
const float *Y, const int incY, float *A, const int lda);
GSL_EXPORT void cblas_ssyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, float *A, const int lda);
GSL_EXPORT void cblas_sspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, float *Ap);
GSL_EXPORT void cblas_ssyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, const float *Y, const int incY, float *A,
const int lda);
GSL_EXPORT void cblas_sspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, const float *Y, const int incY, float *A);
GSL_EXPORT void cblas_dsymv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *A,
const int lda, const double *X, const int incX,
const double beta, double *Y, const int incY);
GSL_EXPORT void cblas_dsbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const double alpha, const double *A,
const int lda, const double *X, const int incX,
const double beta, double *Y, const int incY);
GSL_EXPORT void cblas_dspmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *Ap,
const double *X, const int incX,
const double beta, double *Y, const int incY);
GSL_EXPORT void cblas_dger(const enum CBLAS_ORDER order, const int M, const int N,
const double alpha, const double *X, const int incX,
const double *Y, const int incY, double *A, const int lda);
GSL_EXPORT void cblas_dsyr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, double *A, const int lda);
GSL_EXPORT void cblas_dspr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, double *Ap);
GSL_EXPORT void cblas_dsyr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, const double *Y, const int incY, double *A,
const int lda);
GSL_EXPORT void cblas_dspr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, const double *Y, const int incY, double *A);
/*
* Routines with C and Z prefixes only
*/
GSL_EXPORT void cblas_chemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_chbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_chpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *Ap,
const void *X, const int incX,
const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_cgeru(const enum CBLAS_ORDER order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
GSL_EXPORT void cblas_cgerc(const enum CBLAS_ORDER order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
GSL_EXPORT void cblas_cher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const void *X, const int incX,
void *A, const int lda);
GSL_EXPORT void cblas_chpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const void *X,
const int incX, void *A);
GSL_EXPORT void cblas_cher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
GSL_EXPORT void cblas_chpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *Ap);
GSL_EXPORT void cblas_zhemv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_zhbmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_zhpmv(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *Ap,
const void *X, const int incX,
const void *beta, void *Y, const int incY);
GSL_EXPORT void cblas_zgeru(const enum CBLAS_ORDER order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
GSL_EXPORT void cblas_zgerc(const enum CBLAS_ORDER order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
GSL_EXPORT void cblas_zher(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const void *X, const int incX,
void *A, const int lda);
GSL_EXPORT void cblas_zhpr(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const void *X,
const int incX, void *A);
GSL_EXPORT void cblas_zher2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
GSL_EXPORT void cblas_zhpr2(const enum CBLAS_ORDER order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *Ap);
/*
* ===========================================================================
* Prototypes for level 3 BLAS
* ===========================================================================
*/
/*
* Routines with standard 4 prefixes (S, D, C, Z)
*/
GSL_EXPORT void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const float alpha, const float *A,
const int lda, const float *B, const int ldb,
const float beta, float *C, const int ldc);
GSL_EXPORT void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const float alpha, const float *A, const int lda,
const float *B, const int ldb, const float beta,
float *C, const int ldc);
GSL_EXPORT void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const float alpha, const float *A, const int lda,
const float beta, float *C, const int ldc);
GSL_EXPORT void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const float alpha, const float *A, const int lda,
const float *B, const int ldb, const float beta,
float *C, const int ldc);
GSL_EXPORT void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const float alpha, const float *A, const int lda,
float *B, const int ldb);
GSL_EXPORT void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const float alpha, const float *A, const int lda,
float *B, const int ldb);
GSL_EXPORT void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const double alpha, const double *A,
const int lda, const double *B, const int ldb,
const double beta, double *C, const int ldc);
GSL_EXPORT void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const double alpha, const double *A, const int lda,
const double *B, const int ldb, const double beta,
double *C, const int ldc);
GSL_EXPORT void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const double alpha, const double *A, const int lda,
const double beta, double *C, const int ldc);
GSL_EXPORT void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const double alpha, const double *A, const int lda,
const double *B, const int ldb, const double beta,
double *C, const int ldc);
GSL_EXPORT void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const double alpha, const double *A, const int lda,
double *B, const int ldb);
GSL_EXPORT void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const double alpha, const double *A, const int lda,
double *B, const int ldb);
GSL_EXPORT void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const void *alpha, const void *A,
const int lda, const void *B, const int ldb,
const void *beta, void *C, const int ldc);
GSL_EXPORT void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
GSL_EXPORT void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *beta, void *C, const int ldc);
GSL_EXPORT void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
GSL_EXPORT void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
GSL_EXPORT void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
GSL_EXPORT void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const void *alpha, const void *A,
const int lda, const void *B, const int ldb,
const void *beta, void *C, const int ldc);
GSL_EXPORT void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
GSL_EXPORT void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *beta, void *C, const int ldc);
GSL_EXPORT void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
GSL_EXPORT void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
GSL_EXPORT void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
/*
* Routines with prefixes C and Z only
*/
GSL_EXPORT void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
GSL_EXPORT void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const float alpha, const void *A, const int lda,
const float beta, void *C, const int ldc);
GSL_EXPORT void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const float beta,
void *C, const int ldc);
GSL_EXPORT void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
GSL_EXPORT void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const double alpha, const void *A, const int lda,
const double beta, void *C, const int ldc);
GSL_EXPORT void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const double beta,
void *C, const int ldc);
GSL_EXPORT void cblas_xerbla(int p, const char *rout, const char *form, ...);
__END_DECLS
#endif /* __GSL_CBLAS_H__ */
| {
"alphanum_fraction": 0.57758176,
"avg_line_length": 63.7697368421,
"ext": "h",
"hexsha": "98671151a507122355452ce1024518710c4d6581",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f6ed9b75408f7ce6100ed59b7754f745e59be152",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "dynaryu/vaws",
"max_forks_repo_path": "src/core/gsl/include/gsl/gsl_cblas.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6ed9b75408f7ce6100ed59b7754f745e59be152",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "dynaryu/vaws",
"max_issues_repo_path": "src/core/gsl/include/gsl/gsl_cblas.h",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6ed9b75408f7ce6100ed59b7754f745e59be152",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "dynaryu/vaws",
"max_stars_repo_path": "src/core/gsl/include/gsl/gsl_cblas.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9140,
"size": 38772
} |
#include <pygsl/utils.h>
#include <pygsl/block_helpers.h>
#include <pygsl/error_helpers.h>
#include <gsl/gsl_qrng.h>
#include <pygsl/error_helpers.h>
#include "qrng_module_defines.h"
static PyObject *module = NULL;
static void /* generic instance destruction */
generic_dealloc (PyObject *self)
{
DEBUG_MESS(1, " *** generic_dealloc %p\n", (void *) self);
PyObject_Del(self);
}
/*---------------------------------------------------------------------------*/
/* encapsulation for the PyGSL_qrng_type */
typedef struct {
PyObject_HEAD
gsl_qrng_type * qrng_type;
const char * py_name; /* can not use the name here... niederreiter-*/
} PyGSL_qrng_type;
/*
PyObject*
qrng_type_getattr(PyGSL_qrng_type *self, char *name)
{
if(strcmp(name, "__doc__") == 0){
return PyGSL_get_docobject_for_object(self->py_name);
}else{
Py_INCREF(Py_None);
return Py_None;
}
}
*/
static PyTypeObject PyGSL_qrng_type_pytype = {
PyObject_HEAD_INIT(NULL) /* fix up the type slot in initcrng */
0, /* ob_size */
"PyGSL_qrng_type", /* tp_name */
sizeof(PyGSL_qrng_type), /* tp_basicsize */
0, /* tp_itemsize */
/* standard methods */
(destructor) generic_dealloc, /* tp_dealloc ref-count==0 */
(printfunc) 0, /* tp_print "print x" */
(getattrfunc) 0/*qrng_type_getattr*/, /* tp_getattr "x.attr" */
(setattrfunc) 0, /* tp_setattr "x.attr=v" */
(cmpfunc) 0, /* tp_compare "x > y" */
(reprfunc) 0, /* tp_repr `x`, print x */
/* type categories */
0, /* tp_as_number +,-,*,/,%,&,>>,pow...*/
0, /* tp_as_sequence +,[i],[i:j],len, ...*/
0, /* tp_as_mapping [key], len, ...*/
/* more methods */
(hashfunc) 0, /* tp_hash "dict[x]" */
(ternaryfunc) 0, /* tp_call "x()" */
(reprfunc) 0, /* tp_str "str(x)" */
(getattrofunc) 0, /* tp_getattro */
(setattrofunc) 0, /* tp_setattro */
0, /* tp_as_buffer */
0L, /* tp_flags */
NULL/* PyGSL_qrng_type_pytype_doc*/ /* tp_doc */
};
void
create_qrng_types(PyObject *module)
{
PyGSL_qrng_type *a_rng = NULL;
const gsl_qrng_type* thisRNGType,
*types[3] = {gsl_qrng_niederreiter_2, gsl_qrng_sobol, NULL};
const char* gsl_qrng_names[3] = {"_qrng.niederreiter_2", "_qrng.sobol", NULL};
PyObject* module_dict=PyModule_GetDict(module);
PyObject* item = NULL;
int i;
assert(module_dict);
FUNC_MESS_BEGIN();
/* provide other rng types as subclasses of rng */
for(i=0; types[i]!=NULL; i++){
thisRNGType = types[i];
a_rng = PyObject_NEW(PyGSL_qrng_type, &PyGSL_qrng_type_pytype);
a_rng->qrng_type = (gsl_qrng_type *) thisRNGType;
item = PyString_FromString((thisRNGType)->name);
assert(item);
PyGSL_clear_name(PyString_AsString(item), PyString_Size(item));
assert(gsl_qrng_names[i]);
a_rng->py_name = gsl_qrng_names[i];
PyDict_SetItem(module_dict, item, (PyObject *) a_rng);
Py_DECREF(item);
item = NULL;
thisRNGType++;
}
FUNC_MESS_END();
}
#define PyGSL_QRngType_Check(v) ((v)->ob_type == &PyGSL_qrng_type_pytype)
/*---------------------------------------------------------------------------*/
/* qrng */
staticforward PyTypeObject PyGSL_qrng_pytype;
#if 1
typedef struct {
PyObject_HEAD
gsl_qrng * qrng;
} PyGSL_qrng;
#endif
static void qrng_delete(PyGSL_qrng *self);
static PyObject * /* on "instance.attr" */
qrng_getattr (PyGSL_qrng *self, char *name);
static PyObject *
qrng_get(PyGSL_qrng *self, PyObject *args);
static PyTypeObject PyGSL_qrng_pytype = {
PyObject_HEAD_INIT(NULL) /* fix up the type slot in initcrng */
0, /* ob_size */
"PyGSL_qrng", /* tp_name */
sizeof(PyGSL_qrng), /* tp_basicsize */
0, /* tp_itemsize */
/* standard methods */
(destructor) qrng_delete, /* tp_dealloc ref-count==0 */
(printfunc) 0, /* tp_print "print x" */
(getattrfunc) qrng_getattr, /* tp_getattr "x.attr" */
(setattrfunc) 0, /* tp_setattr "x.attr=v" */
(cmpfunc) 0, /* tp_compare "x > y" */
(reprfunc) 0, /* tp_repr `x`, print x */
/* type categories */
0, /* tp_as_number +,-,*,/,%,&,>>,pow...*/
0, /* tp_as_sequence +,[i],[i:j],len, ...*/
0, /* tp_as_mapping [key], len, ...*/
/* more methods */
(hashfunc) 0, /* tp_hash "dict[x]" */
(ternaryfunc) qrng_get, /* tp_call "x()" */
(reprfunc) 0, /* tp_str "str(x)" */
(getattrofunc) 0, /* tp_getattro */
(setattrofunc) 0, /* tp_setattro */
0, /* tp_as_buffer */
0L, /* tp_flags */
0 /* tp_doc */
};
#define PyGSLQRng_Check(v) ((v)->ob_type == &PyGSL_qrng_pytype)
PyObject *
qrng_init(PyObject *self, PyObject *args)
{
PyObject *type = NULL;
PyGSL_qrng *qrng = NULL;
int dimension;
assert(args);
if (0 == PyArg_ParseTuple(args, "O!i:rng.__init__", &PyGSL_qrng_type_pytype,
&type, &dimension)){
PyGSL_add_traceback(module, __FILE__, "rng.__init__", __LINE__ - 2);
return NULL;
}
if (dimension <= 0){
PyErr_SetString(PyExc_ValueError, "The sample number must be positive!");
PyGSL_add_traceback(module, __FILE__, "qrng.__init__", __LINE__ - 2);
return NULL;
}
qrng = (PyGSL_qrng *) PyObject_NEW(PyGSL_qrng, &PyGSL_qrng_pytype);
qrng->qrng = gsl_qrng_alloc(((PyGSL_qrng_type *)type)->qrng_type, dimension);
return (PyObject *) qrng;
}
static void
qrng_delete(PyGSL_qrng *self)
{
assert(PyGSLQRng_Check(self));
gsl_qrng_free(self->qrng);
DEBUG_MESS(1, " self %p\n",(void *) self);
}
static PyObject *
qrng_reinit(PyGSL_qrng *self, PyObject *args)
{
assert(PyGSLQRng_Check(self));
gsl_qrng_init(self->qrng);
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *
qrng_get(PyGSL_qrng *self, PyObject *args)
{
int dimension = 1, lineno=0;
PyArrayObject *a_array;
PyGSL_array_index_t dims[2];
double *data;
int i;
FUNC_MESS_BEGIN();
assert(PyGSLQRng_Check(self));
if(0 == PyArg_ParseTuple(args, "|i", &dimension)){
goto fail;
}
if(dimension <= 0){
lineno = __LINE__ - 1;
PyErr_SetString(PyExc_ValueError,
"The sample number must be positive!");
goto fail;
}
dims[0] = dimension;
dims[1] = self->qrng->dimension;
DEBUG_MESS(5, "Building return array with dimensions (%ld,%ld)", (long)dims[0], (long)dims[1]);
a_array = (PyArrayObject *) PyGSL_New_Array(2, dims, PyArray_DOUBLE);
if(a_array == NULL){lineno = __LINE__ - 1; goto fail;}
DEBUG_MESS(5, "Its strides are (%d,%d)", a_array->strides[0], a_array->strides[1]);
assert((a_array->strides[1] / sizeof(double)) == 1);
for(i=0; i<dimension; i++){
DEBUG_MESS(6, "Setting slice %d", i);
data = (double *) (a_array->data + a_array->strides[0] * i);
DEBUG_MESS(6, "Data at %p", (void *) data);
gsl_qrng_get(self->qrng, data);
}
FUNC_MESS_END();
return (PyObject *) a_array;
fail:
FUNC_MESS("In Fail!");
PyGSL_add_traceback(module, __FILE__, "_qrng.__attr__", lineno);
return NULL;
}
static PyObject *
qrng_name(PyGSL_qrng *self, PyObject *args)
{
assert(PyGSLQRng_Check(self));
if(0 == PyArg_ParseTuple(args, ":name"))
return NULL;
return PyString_FromString(gsl_qrng_name(self->qrng));
}
static PyObject *
qrng_clone(PyGSL_qrng *self, PyObject *args)
{
PyGSL_qrng * qrng;
assert(PyGSLQRng_Check(self));
if(0 == PyArg_ParseTuple(args, ":clone"))
return NULL;
qrng = (PyGSL_qrng *) PyObject_NEW(PyGSL_qrng, &PyGSL_qrng_pytype);
qrng->qrng = gsl_qrng_clone(self->qrng);
return (PyObject *) qrng;
}
static struct PyMethodDef qrng_methods[] = {
{"init", (PyCFunction) qrng_reinit, METH_VARARGS, QRNG_INIT},
{"get", (PyCFunction) qrng_get, METH_VARARGS, QRNG_GET},
{"name", (PyCFunction) qrng_name, METH_VARARGS, QRNG_NAME},
{"clone", (PyCFunction) qrng_clone, METH_VARARGS, QRNG_CLONE},
{"__copy__", (PyCFunction) qrng_clone, METH_VARARGS, QRNG_CLONE},
{NULL, NULL}
};
static PyObject * /* on "instance.attr" */
qrng_getattr (PyGSL_qrng *self, char *name){
PyObject *tmp = NULL;
assert(PyGSLQRng_Check(self));
/*
if(strcmp(name, "__doc__") == 0)
return PyGSL_get_docobject_for_object("qrng.qrng");
*/
tmp = Py_FindMethod(qrng_methods, (PyObject *) self, name);
if(NULL == tmp){
PyGSL_add_traceback(module, __FILE__, "qrng.__attr__", __LINE__ - 1);
return NULL;
}
return tmp;
}
static PyMethodDef PyGSL_qrng_module_functions[] = {
{"qrng", qrng_init, METH_VARARGS},
{0, 0}
};
void
init_qrng(void)
{
PyObject *m;
m = Py_InitModule("_qrng", PyGSL_qrng_module_functions);
init_pygsl();
assert(m);
create_qrng_types(m);
module = m;
PyGSL_qrng_type_pytype.ob_type = &PyType_Type;
PyGSL_qrng_pytype.ob_type = &PyType_Type;
/*
{
PyObject *o, *s, *d;
d = PyModule_GetDict(m);
s = PyGSL_get_docobject_for_object("_qrng");
if(s)
PyDict_SetItemString(d, "__doc__", s);
o = PyGSL_get_docobject_for_object("_qrng.PyGSL_qrng_type");
if(o){
Py_INCREF(o);
PyGSL_qrng_type_pytype.tp_doc = PyString_AsString(o);
}
o = PyGSL_get_docobject_for_object("_qrng.PyGSL_qrng");
if(o){
Py_INCREF(o);
PyGSL_qrng_type_pytype.tp_doc = PyString_AsString(o);
}
}
*/
}
| {
"alphanum_fraction": 0.6092419522,
"avg_line_length": 28.8323353293,
"ext": "c",
"hexsha": "a5ce913c2b5ab2199cbf657811a7b60656cf8f07",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-10-02T06:18:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-10-02T06:18:07.000Z",
"max_forks_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "juhnowski/FishingRod",
"max_forks_repo_path": "production/pygsl-0.9.5/src/qrng_module.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "juhnowski/FishingRod",
"max_issues_repo_path": "production/pygsl-0.9.5/src/qrng_module.c",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "juhnowski/FishingRod",
"max_stars_repo_path": "production/pygsl-0.9.5/src/qrng_module.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3029,
"size": 9630
} |
/*
* This module must not depend on any other as it is needed during the startup
* of pygsl.
*/
#include <Python.h>
#include <gsl/gsl_errno.h>
#include <pygsl/errorno.h>
static int
add_errno(PyObject * dict, int num, char * name)
{
PyObject * item;
item = PyInt_FromLong(num);
if(item == NULL){
fprintf(stderr, "Failed to generate PyInt with value %d for errno %s\n",
num, name);
return -1;
}
if(PyDict_SetItemString(dict, name, item) == -1){
fprintf(stderr, "Failed to add PyInt %p with value %d to dict %p for errno %s\n",
(void *) item, num, (void *) dict, name);
return -1;
}
return 0;
}
#define ADD_ERRNO(ERRNO, ERRNOSTR) if(add_errno(dict, ERRNO, ERRNOSTR) != 0) goto fail
static PyMethodDef errornoMethods[] = {
{NULL, NULL, 0, NULL}
};
DL_EXPORT(void) initerrno(void)
{
PyObject *dict=NULL, *m=NULL;
m = Py_InitModule("errno", errornoMethods);
assert(m);
dict = PyModule_GetDict(m);
if(!dict)
goto fail;
ADD_ERRNO(GSL_SUCCESS , "GSL_SUCCESS" );
ADD_ERRNO(GSL_FAILURE , "GSL_FAILURE" );
ADD_ERRNO(GSL_CONTINUE, "GSL_CONTINUE");
ADD_ERRNO(GSL_EDOM , "GSL_EDOM" );
ADD_ERRNO(GSL_ERANGE , "GSL_ERANGE" );
ADD_ERRNO(GSL_EFAULT , "GSL_EFAULT" );
ADD_ERRNO(GSL_EINVAL , "GSL_EINVAL" );
ADD_ERRNO(GSL_EFAILED , "GSL_EFAILED" );
ADD_ERRNO(GSL_EFACTOR , "GSL_EFACTOR" );
ADD_ERRNO(GSL_ESANITY , "GSL_ESANITY" );
ADD_ERRNO(GSL_ENOMEM , "GSL_ENOMEM" );
ADD_ERRNO(GSL_EBADFUNC, "GSL_EBADFUNC");
ADD_ERRNO(GSL_ERUNAWAY, "GSL_ERUNAWAY");
ADD_ERRNO(GSL_EMAXITER, "GSL_EMAXITER");
ADD_ERRNO(GSL_EZERODIV, "GSL_EZERODIV");
ADD_ERRNO(GSL_EBADTOL , "GSL_EBADTOL" );
ADD_ERRNO(GSL_ETOL , "GSL_ETOL" );
ADD_ERRNO(GSL_EUNDRFLW, "GSL_EUNDRFLW");
ADD_ERRNO(GSL_EOVRFLW , "GSL_EOVRFLW" );
ADD_ERRNO(GSL_ELOSS , "GSL_ELOSS" );
ADD_ERRNO(GSL_EROUND , "GSL_EROUND" );
ADD_ERRNO(GSL_EBADLEN , "GSL_EBADLEN" );
ADD_ERRNO(GSL_ENOTSQR , "GSL_ENOTSQR" );
ADD_ERRNO(GSL_ESING , "GSL_ESING" );
ADD_ERRNO(GSL_EDIVERGE, "GSL_EDIVERGE");
ADD_ERRNO(GSL_EUNSUP , "GSL_EUNSUP" );
ADD_ERRNO(GSL_EUNIMPL , "GSL_EUNIMPL" );
ADD_ERRNO(GSL_ECACHE , "GSL_ECACHE" );
ADD_ERRNO(GSL_ETABLE , "GSL_ETABLE" );
ADD_ERRNO(GSL_ENOPROG , "GSL_ENOPROG" );
ADD_ERRNO(GSL_ENOPROGJ, "GSL_ENOPROGJ");
ADD_ERRNO(GSL_ETOLF , "GSL_ETOLF" );
ADD_ERRNO(GSL_ETOLX , "GSL_ETOLX" );
ADD_ERRNO(GSL_ETOLG , "GSL_ETOLG" );
ADD_ERRNO(GSL_EOF , "GSL_EOF" );
ADD_ERRNO(PyGSL_ESTRIDE, "PyGSL_ESTRIDE");
return;
fail:
fprintf(stderr, "Initialisation of module errorno failed!\n");
return;
}
| {
"alphanum_fraction": 0.6391678623,
"avg_line_length": 31.6818181818,
"ext": "c",
"hexsha": "c036a639b1e7384fe2a755d2206ec8b0127d4999",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-10-02T06:18:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-10-02T06:18:07.000Z",
"max_forks_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "juhnowski/FishingRod",
"max_forks_repo_path": "production/pygsl-0.9.5/src/init/errorno.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "juhnowski/FishingRod",
"max_issues_repo_path": "production/pygsl-0.9.5/src/init/errorno.c",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "457e7afb5cab424296dff95e1acf10ebf70d32a9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "juhnowski/FishingRod",
"max_stars_repo_path": "production/pygsl-0.9.5/src/init/errorno.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 979,
"size": 2788
} |
#pragma once
#include <halley/utils/utils.h>
#include <vector>
#include <gsl/gsl>
#include "halley/data_structures/flat_map.h"
#include "halley/maths/vector2.h"
#include "halley/maths/rect.h"
#include "halley/file/path.h"
#include <map>
#include <unordered_map>
#include <cstdint>
#include <utility>
#include <set>
#include "halley/data_structures/maybe.h"
#include "halley/maths/colour.h"
#include "halley/maths/vector4.h"
namespace Halley {
class String;
class SerializerOptions {
public:
constexpr static int maxVersion = 1;
int version = 0;
bool exhaustiveDictionary = false;
std::function<std::optional<size_t>(const String& string)> stringToIndex;
std::function<const String&(size_t index)> indexToString;
SerializerOptions() = default;
SerializerOptions(int version)
: version(version)
{}
};
class SerializerState {};
class ByteSerializationBase {
public:
ByteSerializationBase(SerializerOptions options)
: options(std::move(options))
{}
SerializerState* setState(SerializerState* state);
template <typename T>
T* getState() const
{
return static_cast<T*>(state);
}
int getVersion() const { return version; }
void setVersion(int v) { version = v; }
protected:
SerializerOptions options;
private:
SerializerState* state = nullptr;
int version = 0;
};
class Serializer : public ByteSerializationBase {
public:
Serializer(SerializerOptions options);
explicit Serializer(gsl::span<gsl::byte> dst, SerializerOptions options);
template <typename T, typename std::enable_if<std::is_convertible<T, std::function<void(Serializer&)>>::value, int>::type = 0>
static Bytes toBytes(const T& f, SerializerOptions options = {})
{
auto dry = Serializer(options);
f(dry);
Bytes result(dry.getSize());
auto s = Serializer(gsl::as_writable_bytes(gsl::span<Halley::Byte>(result)), options);
f(s);
return result;
}
template <typename T, typename std::enable_if<!std::is_convertible<T, std::function<void(Serializer&)>>::value, int>::type = 0>
static Bytes toBytes(const T& value, SerializerOptions options = {})
{
return toBytes([&value](Serializer& s) { s << value; }, options);
}
size_t getSize() const { return size; }
Serializer& operator<<(bool val) { return serializePod(val); }
Serializer& operator<<(int8_t val) { return serializeInteger(val); }
Serializer& operator<<(uint8_t val) { return serializeInteger(val); }
Serializer& operator<<(int16_t val) { return serializeInteger(val); }
Serializer& operator<<(uint16_t val) { return serializeInteger(val); }
Serializer& operator<<(int32_t val) { return serializeInteger(val); }
Serializer& operator<<(uint32_t val) { return serializeInteger(val); }
Serializer& operator<<(int64_t val) { return serializeInteger(val); }
Serializer& operator<<(uint64_t val) { return serializeInteger(val); }
Serializer& operator<<(float val) { return serializePod(val); }
Serializer& operator<<(double val) { return serializePod(val); }
Serializer& operator<<(const std::string& str);
Serializer& operator<<(const String& str);
Serializer& operator<<(const StringUTF32& str);
Serializer& operator<<(const Path& path);
Serializer& operator<<(gsl::span<const gsl::byte> span);
Serializer& operator<<(const Bytes& bytes);
template <typename T>
Serializer& operator<<(const std::vector<T>& val)
{
unsigned int sz = static_cast<unsigned int>(val.size());
*this << sz;
for (unsigned int i = 0; i < sz; i++) {
*this << val[i];
}
return *this;
}
template <typename T>
Serializer& operator<<(const std::list<T>& val)
{
unsigned int sz = static_cast<unsigned int>(val.size());
*this << sz;
for (const auto& v: val) {
*this << v;
}
return *this;
}
template <typename T, typename U>
Serializer& operator<<(const FlatMap<T, U>& val)
{
*this << static_cast<unsigned int>(val.size());
for (auto& kv : val) {
*this << kv.first << kv.second;
}
return *this;
}
template <typename K, typename V, typename Cmp, typename Allocator>
Serializer& operator<<(const std::map<K, V, Cmp, Allocator>& val)
{
*this << static_cast<unsigned int>(val.size());
for (auto& kv : val) {
*this << kv.first << kv.second;
}
return *this;
}
template <typename T, typename U>
Serializer& operator<<(const std::unordered_map<T, U>& val)
{
std::map<T, U> m;
for (auto& kv: val) {
m[kv.first] = kv.second;
}
return (*this << m);
}
template <typename T>
Serializer& operator<<(const std::set<T>& val)
{
unsigned int sz = static_cast<unsigned int>(val.size());
*this << sz;
for (auto& v: val) {
*this << v;
}
return *this;
}
template <typename T>
Serializer& operator<<(const Vector2D<T>& val)
{
return *this << val.x << val.y;
}
template <typename T>
Serializer& operator<<(const Vector4D<T>& val)
{
return *this << val.x << val.y << val.z << val.w;
}
template <typename T>
Serializer& operator<<(const Colour4<T>& val)
{
return *this << val.r << val.g << val.b << val.a;
}
template <typename T>
Serializer& operator<<(const Rect2D<T>& val)
{
return *this << val.getTopLeft() << val.getBottomRight();
}
template <typename T, typename U>
Serializer& operator<<(const std::pair<T, U>& p)
{
return *this << p.first << p.second;
}
template <typename T>
Serializer& operator<<(const std::optional<T>& p)
{
if (p) {
return *this << true << p.value();
} else {
return *this << false;
}
}
template <typename T>
Serializer& operator<<(const Range<T>& p)
{
return *this << p.start << p.end;
}
template <typename T, std::enable_if_t<std::is_enum<T>::value == true, int> = 0>
Serializer& operator<<(const T& val)
{
using B = typename std::underlying_type<T>::type;
return *this << B(val);
}
template <typename T, std::enable_if_t<std::is_enum<T>::value == false, int> = 0>
Serializer& operator<<(const T& val)
{
val.serialize(*this);
return *this;
}
size_t getPosition() const { return size; }
private:
size_t size = 0;
gsl::span<gsl::byte> dst;
bool dryRun;
template <typename T>
Serializer& serializePod(T val)
{
if (!dryRun) {
memcpy(dst.data() + size, &val, sizeof(T));
}
size += sizeof(T);
return *this;
}
template <typename T>
Serializer& serializeInteger(T val)
{
if (options.version >= 1) {
// Variable-length
if constexpr (std::is_signed_v<T>) {
serializeVariableInteger(static_cast<uint64_t>(val >= 0 ? val : -(val + 1)), val < 0);
} else {
serializeVariableInteger(val, {});
}
return *this;
} else {
// Fixed length
return serializePod(val);
}
}
void serializeVariableInteger(uint64_t val, std::optional<bool> sign);
};
class Deserializer : public ByteSerializationBase {
public:
Deserializer(gsl::span<const gsl::byte> src, SerializerOptions options = {});
Deserializer(const Bytes& src, SerializerOptions options = {});
template <typename T>
static T fromBytes(const Bytes& src, SerializerOptions options = {})
{
T result;
Deserializer s(src, std::move(options));
s >> result;
return result;
}
template <typename T>
static T fromBytes(gsl::span<const gsl::byte> src, SerializerOptions options = {})
{
T result;
Deserializer s(src, std::move(options));
s >> result;
return result;
}
template <typename T>
static void fromBytes(T& target, const Bytes& src, SerializerOptions options = {})
{
Deserializer s(src, std::move(options));
s >> target;
}
template <typename T>
static void fromBytes(T& target, gsl::span<const gsl::byte> src, SerializerOptions options = {})
{
Deserializer s(src, std::move(options));
s >> target;
}
Deserializer& operator>>(bool& val) { return deserializePod(val); }
Deserializer& operator>>(int8_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(uint8_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(int16_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(uint16_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(int32_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(uint32_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(int64_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(uint64_t& val) { return deserializeInteger(val); }
Deserializer& operator>>(float& val) { return deserializePod(val); }
Deserializer& operator>>(double& val) { return deserializePod(val); }
Deserializer& operator>>(std::string& str);
Deserializer& operator>>(String& str);
Deserializer& operator>>(StringUTF32& str);
Deserializer& operator>>(Path& p);
Deserializer& operator>>(gsl::span<gsl::byte> span);
Deserializer& operator>>(Bytes& bytes);
template <typename T>
Deserializer& operator>>(std::vector<T>& val)
{
unsigned int sz;
*this >> sz;
ensureSufficientBytesRemaining(sz); // Expect at least one byte per vector entry
val.clear();
val.reserve(sz);
for (unsigned int i = 0; i < sz; i++) {
val.push_back(T());
*this >> val[i];
}
return *this;
}
template <typename T>
Deserializer& operator>>(std::list<T>& val)
{
unsigned int sz;
*this >> sz;
ensureSufficientBytesRemaining(sz); // Expect at least one byte per vector entry
val.clear();
for (unsigned int i = 0; i < sz; i++) {
T v;
*this >> v;
val.push_back(std::move(v));
}
return *this;
}
template <typename T, typename U>
Deserializer& operator>>(FlatMap<T, U>& val)
{
unsigned int sz;
*this >> sz;
ensureSufficientBytesRemaining(sz * 2); // Expect at least two bytes per map entry
std::vector<std::pair<T, U>> tmpData(sz);
for (unsigned int i = 0; i < sz; i++) {
*this >> tmpData[i].first >> tmpData[i].second;
}
val = FlatMap<T, U>(boost::container::ordered_unique_range_t(), tmpData.begin(), tmpData.end());
return *this;
}
template <typename K, typename V, typename Cmp, typename Allocator>
Deserializer& operator >> (std::map<K, V, Cmp, Allocator>& val)
{
unsigned int sz;
*this >> sz;
ensureSufficientBytesRemaining(size_t(sz) * 2); // Expect at least two bytes per map entry
for (unsigned int i = 0; i < sz; i++) {
K key;
V value;
*this >> key >> value;
val[key] = std::move(value);
}
return *this;
}
template <typename T, typename U>
Deserializer& operator >> (std::unordered_map<T, U>& val)
{
unsigned int sz;
*this >> sz;
ensureSufficientBytesRemaining(sz * 2); // Expect at least two bytes per map entry
for (unsigned int i = 0; i < sz; i++) {
T key;
U value;
*this >> key >> value;
val[key] = std::move(value);
}
return *this;
}
template <typename T>
Deserializer& operator>>(std::set<T>& val)
{
unsigned int sz;
*this >> sz;
ensureSufficientBytesRemaining(sz); // Expect at least one byte per set entry
val.clear();
for (unsigned int i = 0; i < sz; i++) {
T v;
*this >> v;
val.insert(std::move(v));
}
return *this;
}
template <typename T>
Deserializer& operator>>(Vector2D<T>& val)
{
*this >> val.x;
*this >> val.y;
return *this;
}
template <typename T>
Deserializer& operator>>(Vector4D<T>& val)
{
*this >> val.x;
*this >> val.y;
*this >> val.z;
*this >> val.w;
return *this;
}
template <typename T>
Deserializer& operator>>(Colour4<T>& val)
{
*this >> val.r;
*this >> val.g;
*this >> val.b;
*this >> val.a;
return *this;
}
template <typename T>
Deserializer& operator>>(Rect2D<T>& val)
{
Vector2D<T> p1, p2;
*this >> p1;
*this >> p2;
val = Rect2D<T>(p1, p2);
return *this;
}
template <typename T, typename U>
Deserializer& operator>>(std::pair<T, U>& p)
{
return *this >> p.first >> p.second;
}
template <typename T>
Deserializer& operator>>(Range<T>& p)
{
return *this >> p.start >> p.end;
}
template <typename T>
Deserializer& operator>>(std::optional<T>& p)
{
bool present;
*this >> present;
if (present) {
T tmp;
*this >> tmp;
p = tmp;
} else {
p = std::optional<T>();
}
return *this;
}
template <typename T, std::enable_if_t<std::is_enum<T>::value == true, int> = 0>
Deserializer& operator>>(T& val)
{
typename std::underlying_type<T>::type tmp;
*this >> tmp;
val = T(tmp);
return *this;
}
template <typename T, std::enable_if_t<std::is_enum<T>::value == false, int> = 0>
Deserializer& operator>>(T& val)
{
val.deserialize(*this);
return *this;
}
template <typename T>
void peek(T& val)
{
const auto oldPos = pos;
*this >> val;
pos = oldPos;
}
size_t getPosition() const { return pos; }
private:
size_t pos = 0;
gsl::span<const gsl::byte> src;
template <typename T>
Deserializer& deserializePod(T& val)
{
ensureSufficientBytesRemaining(sizeof(T));
memcpy(&val, src.data() + pos, sizeof(T));
pos += sizeof(T);
return *this;
}
template <typename T>
Deserializer& deserializeInteger(T& val)
{
if (options.version >= 1) {
// Variable-length
bool sign;
uint64_t temp;
deserializeVariableInteger(temp, sign, std::is_signed_v<T>);
if (sign) {
int64_t signedTemp = -int64_t(temp) - 1;
val = static_cast<T>(signedTemp);
} else {
val = static_cast<T>(temp);
}
return *this;
} else {
// Fixed length
return deserializePod(val);
}
}
void deserializeVariableInteger(uint64_t& val, bool& sign, bool isSigned);
void ensureSufficientBytesRemaining(size_t bytes);
size_t getBytesRemaining() const;
};
}
| {
"alphanum_fraction": 0.6385516045,
"avg_line_length": 25.2021857923,
"ext": "h",
"hexsha": "aa6169803aaa1e3ce89e9f924e72314871250691",
"lang": "C",
"max_forks_count": 193,
"max_forks_repo_forks_event_max_datetime": "2022-03-22T12:59:58.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-10-23T06:08:41.000Z",
"max_forks_repo_head_hexsha": "eb395c8cc5ab6fb4aa1966ce3d7a9c1b8301d587",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "JLouhela/halley",
"max_forks_repo_path": "src/engine/utils/include/halley/bytes/byte_serializer.h",
"max_issues_count": 53,
"max_issues_repo_head_hexsha": "eb395c8cc5ab6fb4aa1966ce3d7a9c1b8301d587",
"max_issues_repo_issues_event_max_datetime": "2022-01-10T13:52:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-09T16:25:04.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "JLouhela/halley",
"max_issues_repo_path": "src/engine/utils/include/halley/bytes/byte_serializer.h",
"max_line_length": 129,
"max_stars_count": 3262,
"max_stars_repo_head_hexsha": "eb395c8cc5ab6fb4aa1966ce3d7a9c1b8301d587",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "JLouhela/halley",
"max_stars_repo_path": "src/engine/utils/include/halley/bytes/byte_serializer.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-31T17:47:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-10T15:24:10.000Z",
"num_tokens": 3975,
"size": 13836
} |
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gsl/gsl_statistics_double.h>
#include "tz_error.h"
#include "tz_constant.h"
#include "tz_iarray.h"
#include "tz_image_lib.h"
#include "tz_objdetect.h"
#include "tz_imatrix.h"
#include "tz_stack_math.h"
#include "tz_stack_bwdist.h"
#include "tz_pixel_array.h"
#include "tz_stack_bwmorph.h"
#include "tz_dimage_lib.h"
#include "tz_darray.h"
#include "tz_u8array.h"
#include "tz_stack_objlabel.h"
#include "tz_voxel_linked_list.h"
#include "tz_voxel_graphics.h"
#include "tz_dmatrix.h"
#include "tz_stack_sampling.h"
#include "tz_stack_threshold.h"
INIT_EXCEPTION_MAIN(e)
int main(int argc, char* argv[])
{
char neuron_name[100];
if (argc == 1) {
strcpy(neuron_name, "fly_neuron");
} else {
strcpy(neuron_name, argv[1]);
}
char file_path[100];
sprintf(file_path, "../data/%s/mask.tif", neuron_name);
Stack *mask = Read_Stack(file_path);
sprintf(file_path, "../data/%s/seeds.pa", neuron_name);
Pixel_Array *pa = Pixel_Array_Read(file_path);
double *pa_array = (double *) pa->array;
sprintf(file_path, "../data/%s/seed_offset.ar", neuron_name);
int seed_number = pa->size;
int *seed_offset = (int *) malloc(sizeof(int) * seed_number);
iarray_read(file_path, seed_offset, &seed_number);
int max_idx;
double max_dist = darray_max(pa_array, pa->size, &max_idx);
max_idx = seed_offset[max_idx];
Stack_Label_Object_Dist_N(mask, NULL, max_idx, 1, 2, max_dist * 2.0, 26);
Stack_Threshold_Binarize(mask, 1);
sprintf(file_path, "../data/%s/blobmask.tif", neuron_name);
Write_Stack(file_path, mask);
free(seed_offset);
Kill_Stack(mask);
return 0;
}
| {
"alphanum_fraction": 0.7153937947,
"avg_line_length": 25.3939393939,
"ext": "c",
"hexsha": "34e231d2b300ef35f48151e6d6dbc57beb946f2d",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zzhmark/vaa3d_tools",
"max_forks_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/single_neuron_blobmask.c",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d",
"max_issues_repo_issues_event_max_datetime": "2016-12-03T05:33:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-12-03T05:33:13.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "zzhmark/vaa3d_tools",
"max_issues_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/single_neuron_blobmask.c",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "3ca418add85a59ac7e805d55a600b78330d7e53d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zzhmark/vaa3d_tools",
"max_stars_repo_path": "released_plugins/v3d_plugins/neurontracing_neutube/src_neutube/neurolabi/c/single_neuron_blobmask.c",
"max_stars_repo_stars_event_max_datetime": "2021-12-27T19:14:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-27T19:14:03.000Z",
"num_tokens": 477,
"size": 1676
} |
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#ifdef __APPLE__
#include <cblas.h>
#include <libiomp/omp.h>
#define set_num_threads(x) openblas_set_num_threads(x)
#define get_num_threads() openblas_get_num_threads()
#else
#include <mkl.h>
#include <omp.h>
#define set_num_threads(x) mkl_set_num_threads(x)
#define get_num_threads() mkl_get_num_threads()
#endif
double norm_inf_mat_Y11(double *X, int n);
int main(int argc, char **argv) {
char *files[] = {
//"1200_m1_t2_hi_c363417000.7.mat.bin",
//"1200_m1_t7_hi_c536234414.4.mat.bin",
//"2340_m2_a1e15_to_c3291.0.mat.bin",
//"5900_m1_t1_to_c3205771604.1.mat.bin",
//"1200_m1_t3_hi_c70487569.2.mat.bin",
//"2340_m1_t1_to_c1446918556.5.mat.bin",
//"2340_m2_a1e5_to_c8.0.mat.bin",
//"5900_m2_a1e15_to_c4198.3.mat.bin",
"494_bus.mtx.bin",
//"bcsstk13.mtx.bin",
//"bcsstk27.mtx.bin",
//"ex9.mtx.bin",
//"msc01050.mtx.bin",
//"bcsstk15.mtx.bin",
//"cage9.mtx.bin",
//"gyro.mtx.bin",
"tomography.mtx.bin"
};
int num_of_files = sizeof(files) / sizeof(char *);
char *file_dir = NULL;
int option = 0, omp_threads = 1;
while ((option = getopt(argc, argv, "f:t:")) != -1) {
switch (option) {
case 'f':
file_dir = optarg;
break;
case 't':
omp_threads = atoi(optarg);
break;
default:
printf("Usage: mpi_mexp -f string -t num_threads \n");
return 0;
}
}
if (file_dir == NULL) {
printf("Usage: mpi_mexp -f string -t num_threads \n");
return 0;
}
set_num_threads(omp_threads);
omp_set_num_threads(omp_threads);
int numTasks, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int qProcs = (int) sqrt(numTasks);
if (qProcs - sqrt(numTasks) != 0) {
if (rank == 0)
printf("np must be a square number\n");
MPI_Finalize();
return 0;
}
int q_root = qProcs - 1;
int world_root = numTasks - 1;
int n, dims[2] = {qProcs, qProcs}, periods[2] = {0, 0}, reorder = 0, coords[2], rc, i;
MPI_Comm cartComm;
MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, reorder, &cartComm);
MPI_Comm_rank(cartComm, &rank);
MPI_Cart_coords(cartComm, rank, 2, coords);
MPI_Comm rowComm, colComm;
MPI_Comm_split(MPI_COMM_WORLD, coords[0], rank, &rowComm);
MPI_Comm_split(MPI_COMM_WORLD, coords[1], rank, &colComm);
int row_rank, col_rank;
MPI_Comm_rank(colComm, &col_rank);
MPI_Comm_rank(rowComm, &row_rank);
char filename[1024];
while (num_of_files-- > 0) {
memset(filename, 0, strlen(filename));
strcpy(filename, file_dir);
strcat(filename, files[num_of_files]);
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0)
printf("\n%s\n", filename);
MPI_File matFile;
rc = MPI_File_open(cartComm, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &matFile);
if (rc && (rank == 0)) {
printf("Unable to open file %s\n", filename);
fflush(stdout);
}
MPI_Status status;
MPI_File_read(matFile, &n, 1, MPI_INT, &status);
int blockSize = 0, lastBlock = 0;
blockSize = (n + qProcs) / qProcs; /* number of rows in _block_ */
lastBlock = n + 1 - (qProcs - 1) * blockSize;
if (rank == 0) {
printf("size: %d, %d ,%d\n", n, blockSize, lastBlock);
}
double *LocalA = (double *) malloc(blockSize * blockSize * sizeof(double));
MPI_Datatype readFileType;
MPI_Type_vector(blockSize, blockSize, n, MPI_DOUBLE, &readFileType);
MPI_Type_commit(&readFileType);
MPI_Offset offset = (MPI_Offset) (1 * sizeof(int) +
sizeof(double) * (blockSize * coords[1] + blockSize * n * coords[0]));
MPI_File_set_view(matFile, offset, MPI_DOUBLE, readFileType,
"native", MPI_INFO_NULL);
MPI_File_read_at(matFile, 0, LocalA, blockSize * blockSize, MPI_DOUBLE, &status);
MPI_Type_free(&readFileType);
if (coords[0] == q_root) {
memset(LocalA + (lastBlock - 1) * blockSize, 0,
(blockSize + 1 - lastBlock) * blockSize * sizeof(double));
}
if (coords[1] == q_root) {
int kk = 0;
for (kk = 0; kk < blockSize; ++kk) {
memset(LocalA + kk * blockSize + lastBlock - 1, 0, (blockSize + 1 - lastBlock) * sizeof(double));
}
}
double loc_d_var;
double *loc_vec_var = (double *) malloc(blockSize * sizeof(double));
memset(loc_vec_var, 0, blockSize * sizeof(double));
offset = (MPI_Offset) (1 * sizeof(int) + sizeof(double) * n * n);
MPI_File_set_view(matFile, offset, MPI_DOUBLE, MPI_DOUBLE,
"native", MPI_INFO_NULL);
offset = coords[0] * blockSize;
MPI_File_read_at_all(matFile, offset, loc_vec_var, coords[0] == qProcs - 1 ? lastBlock : blockSize, MPI_DOUBLE,
&status);
MPI_File_close(&matFile);
if (coords[1] == qProcs - 1) {
cblas_dcopy(blockSize, loc_vec_var, 1, LocalA + lastBlock - 1, blockSize);
}
double mpi_start = MPI_Wtime();
//compute inf norm of matA
for (i = 0; i < (col_rank == q_root ? lastBlock - 1 : blockSize); ++i) {
loc_vec_var[i] = cblas_dasum((row_rank == q_root ? lastBlock - 1 : blockSize), LocalA + i * blockSize,
1);
}
if (row_rank == q_root) {
MPI_Reduce(MPI_IN_PLACE, loc_vec_var, blockSize, MPI_DOUBLE, MPI_SUM, q_root, rowComm);
} else {
MPI_Reduce(loc_vec_var, loc_vec_var, blockSize, MPI_DOUBLE, MPI_SUM, q_root, rowComm);
}
if (row_rank == q_root) {
loc_d_var = 0;
for (i = 0; i < (col_rank == q_root ? lastBlock - 1 : blockSize); ++i) {
if (loc_vec_var[i] > loc_d_var)
loc_d_var = loc_vec_var[i];
}
if (col_rank == q_root) {
MPI_Reduce(MPI_IN_PLACE, &loc_d_var, 1, MPI_DOUBLE, MPI_MAX, q_root, colComm);
} else {
MPI_Reduce(&loc_d_var, &loc_d_var, 1, MPI_DOUBLE, MPI_MAX, q_root, colComm);
}
}
MPI_Bcast(&loc_d_var, 1, MPI_DOUBLE, world_root, MPI_COMM_WORLD);
//init Y martix
for (i = 0; i < (col_rank == q_root ? lastBlock - 1 : blockSize); ++i) {
cblas_dscal((row_rank == q_root ? lastBlock - 1 : blockSize), -1 / loc_d_var, LocalA + i * blockSize,
1);
}
if (row_rank == q_root) {
cblas_dscal((col_rank == q_root ? lastBlock - 1 : blockSize), 1 / loc_d_var, LocalA + lastBlock - 1,
blockSize);
}
if (row_rank == col_rank) {
for (i = 0; i < (row_rank == q_root ? lastBlock - 1 : blockSize); ++i) {
LocalA[i * blockSize + i] += 1;
}
}
if (rank == world_root) {
LocalA[(lastBlock - 1) * (blockSize + 1)] = 1;
}
//loop
double tolerance = 1e-8;
int loopBreak = 0, iteration = 0;
double *col_mat = (double *) malloc(qProcs * blockSize * blockSize * sizeof(double));
double *row_mat = (double *) malloc(qProcs * blockSize * blockSize * sizeof(double));
while (true) {
//norm mat
//compute inf norm of matA
for (i = 0; i < (col_rank == q_root ? lastBlock - 1 : blockSize); ++i) {
loc_vec_var[i] = cblas_dasum((row_rank == q_root ? lastBlock - 1 : blockSize),
LocalA + i * blockSize, 1);
}
if (row_rank == q_root) {
MPI_Reduce(MPI_IN_PLACE, loc_vec_var, blockSize, MPI_DOUBLE, MPI_SUM, q_root, rowComm);
} else {
MPI_Reduce(loc_vec_var, loc_vec_var, blockSize, MPI_DOUBLE, MPI_SUM, q_root, rowComm);
}
if (row_rank == q_root) {
loc_d_var = 0;
for (i = 0; i < (col_rank == q_root ? lastBlock - 1 : blockSize); ++i) {
if (loc_vec_var[i] > loc_d_var)
loc_d_var = loc_vec_var[i];
}
if (col_rank == q_root) {
MPI_Reduce(MPI_IN_PLACE, &loc_d_var, 1, MPI_DOUBLE, MPI_MAX, q_root, colComm);
} else {
MPI_Reduce(&loc_d_var, &loc_d_var, 1, MPI_DOUBLE, MPI_MAX, q_root, colComm);
}
size_t index = cblas_idamax((col_rank == q_root ? lastBlock - 1 : blockSize),
LocalA + lastBlock - 1,
blockSize);
double norm2b = 0;
MPI_Reduce(&LocalA[index * blockSize + lastBlock - 1], &norm2b, 1, MPI_DOUBLE, MPI_MAX, q_root,
colComm);
if (col_rank == q_root) {
loopBreak = (loc_d_var / norm2b < tolerance) ? 1 : 0;
}
}
MPI_Bcast(&loopBreak, 1, MPI_INT, world_root, MPI_COMM_WORLD);
if (loopBreak > 0)
break;
iteration++;
//gather loc mat
MPI_Allgather(LocalA, blockSize * blockSize, MPI_DOUBLE, col_mat, blockSize * blockSize, MPI_DOUBLE,
colComm);
MPI_Allgather(LocalA, blockSize * blockSize, MPI_DOUBLE, row_mat, blockSize * blockSize, MPI_DOUBLE,
rowComm);
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, blockSize, blockSize, blockSize,
1, row_mat, blockSize, col_mat, blockSize, 0.0, LocalA, blockSize);
for (i = 1; i < qProcs; ++i) {
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, blockSize, blockSize, blockSize,
1, row_mat + i * (blockSize * blockSize), blockSize,
col_mat + i * (blockSize * blockSize), blockSize, 1, LocalA, blockSize);
}
}
free(row_mat);
free(col_mat);
free(loc_vec_var);
if (rank == world_root) {
printf("NumProc: %d\n", numTasks);
printf("mpi_mexp_iter: %d\t", iteration);
printf("mpi_mexp_time: %f\n", MPI_Wtime() - mpi_start);
}
if (row_rank == q_root) {
for (i = 0; i < (row_rank == qProcs - 1 ? lastBlock : blockSize); ++i) {
if (fabs(LocalA[i * blockSize + lastBlock - 1] - 1) > 1e-3) {
printf("MPI_MEXP_ERR %f \n", LocalA[i * blockSize + lastBlock - 1]);
break;
}
}
}
free(LocalA);
/*
* MPI_CG
*/
rc = MPI_File_open(cartComm, filename, MPI_MODE_RDONLY, MPI_INFO_NULL, &matFile);
if (rc && (rank == 0)) {
printf("Unable to open file %s\n", filename);
fflush(stdout);
}
MPI_File_read(matFile, &n, 1, MPI_INT, &status);
blockSize = (n + qProcs - 1) / qProcs; /* number of rows in _block_ */
lastBlock = n - (qProcs - 1) * blockSize;
LocalA = (double *) malloc(blockSize * blockSize * sizeof(double));
MPI_Type_vector(blockSize, blockSize, n, MPI_DOUBLE, &readFileType);
MPI_Type_commit(&readFileType);
offset = (MPI_Offset) (1 * sizeof(int) +
sizeof(double) * (blockSize * coords[1] + blockSize * n * coords[0]));
MPI_File_set_view(matFile, offset, MPI_DOUBLE, readFileType,
"native", MPI_INFO_NULL);
MPI_File_read_at(matFile, 0, LocalA, blockSize * blockSize, MPI_DOUBLE, &status);
MPI_Type_free(&readFileType);
if (coords[0] == qProcs - 1) {
memset(LocalA + lastBlock * blockSize, 0, (blockSize - lastBlock) * blockSize * sizeof(double));
}
if (coords[1] == qProcs - 1) {
int kk = 0;
for (kk = 0; kk < blockSize; ++kk) {
memset(LocalA + kk * blockSize + lastBlock, 0, (blockSize - lastBlock) * sizeof(double));
}
}
double *LocalB = (double *) malloc(blockSize * sizeof(double));
memset(LocalB, 0, blockSize * sizeof(double));
offset = (MPI_Offset) (1 * sizeof(int) + sizeof(double) * n * n);
MPI_File_set_view(matFile, offset, MPI_DOUBLE, MPI_DOUBLE,
"native", MPI_INFO_NULL);
offset = coords[1] * blockSize;
MPI_File_read_at_all(matFile, offset, LocalB, coords[1] == qProcs - 1 ? lastBlock : blockSize, MPI_DOUBLE,
&status);
MPI_File_close(&matFile);
mpi_start = MPI_Wtime();
double alpha, beta, rho_new = 0.0, rho_old = 0.0;
iteration = 0;
double *loc_Vr = LocalB; //(double *) malloc(blockSize * sizeof(double));
double *loc_Vp = (double *) malloc(blockSize * sizeof(double));
double *loc_Vw = (double *) malloc(blockSize * sizeof(double));
double *loc_Vx = (double *) malloc(blockSize * sizeof(double));
//localr <- localB
memset(loc_Vx, 0, blockSize * sizeof(double));
//cblas_dcopy(blockSize, LocalB, 1, loc_Vr, 1);
double b_norm2 = 0;
if (col_rank == qProcs - 1) {
double loc_b_dot = cblas_ddot((row_rank == qProcs - 1 ? lastBlock : blockSize), loc_Vr, 1, loc_Vr, 1);
MPI_Reduce(&loc_b_dot, &rho_new, 1, MPI_DOUBLE, MPI_SUM, qProcs - 1, rowComm);
b_norm2 = sqrt(rho_new);
}
loopBreak = 0;
while (true) {
if (rank == world_root) {
loopBreak = (sqrt(rho_new) / b_norm2 < tolerance) ? 1 : 0;
}
MPI_Bcast(&loopBreak, 1, MPI_INT, world_root, MPI_COMM_WORLD);
if (loopBreak > 0)
break;
iteration++;
if (iteration == 1) {
cblas_dcopy(blockSize, loc_Vr, 1, loc_Vp, 1);
} else {
if (rank == world_root) {
beta = rho_new / rho_old;
}
MPI_Bcast(&beta, 1, MPI_DOUBLE, world_root, MPI_COMM_WORLD);
cblas_dscal((row_rank == qProcs - 1 ? lastBlock : blockSize), beta, loc_Vp, 1);
cblas_daxpy((row_rank == qProcs - 1 ? lastBlock : blockSize), 1.0, loc_Vr, 1, loc_Vp, 1);
}
cblas_dgemv(CblasRowMajor, CblasNoTrans, (col_rank == qProcs - 1 ? lastBlock : blockSize),
(row_rank == qProcs - 1 ? lastBlock : blockSize),
1.0, LocalA, blockSize, loc_Vp, 1, 0.0, loc_Vw, 1);
if (col_rank == row_rank) {
MPI_Reduce(MPI_IN_PLACE, loc_Vw, blockSize, MPI_DOUBLE, MPI_SUM, col_rank, rowComm);
} else {
MPI_Reduce(loc_Vw, loc_Vw, blockSize, MPI_DOUBLE, MPI_SUM, col_rank, rowComm);
}
MPI_Bcast(loc_Vw, (row_rank == qProcs - 1 ? lastBlock : blockSize), MPI_DOUBLE, row_rank, colComm);
if (col_rank == qProcs - 1) {
double loc_pw_dot = cblas_ddot((row_rank == qProcs - 1 ? lastBlock : blockSize), loc_Vp, 1, loc_Vw,
1), glo_pw_dot;
MPI_Reduce(&loc_pw_dot, &glo_pw_dot, 1, MPI_DOUBLE, MPI_SUM, qProcs - 1, rowComm);
if (rank == world_root) {
alpha = rho_new / glo_pw_dot;
}
}
MPI_Bcast(&alpha, 1, MPI_DOUBLE, world_root, MPI_COMM_WORLD);
cblas_daxpy((row_rank == qProcs - 1 ? lastBlock : blockSize), -alpha, loc_Vw, 1, loc_Vr, 1);
if (coords[0] == qProcs - 1) {
rho_old = rho_new;
cblas_daxpy((row_rank == qProcs - 1 ? lastBlock : blockSize), alpha, loc_Vp, 1, loc_Vx, 1);
double loc_r_dot = cblas_ddot(blockSize, loc_Vr, 1, loc_Vr, 1);
MPI_Reduce(&loc_r_dot, &rho_new, 1, MPI_DOUBLE, MPI_SUM, qProcs - 1, rowComm);
}
}
if (rank == world_root) {
printf("mpi_cg_it: %d\t", iteration);
printf("mpi_cg_time: %f\n", MPI_Wtime() - mpi_start);
}
free(LocalA);
free(loc_Vp);
free(loc_Vr);
free(loc_Vw);
if (col_rank == qProcs - 1) {
for (rc = 0; rc < (row_rank == qProcs - 1 ? lastBlock : blockSize); ++rc) {
if (fabs(loc_Vx[rc] - 1) > 1e-3) {
printf("MPI_CG_ERR %f \n", loc_Vx[rc]);
break;
}
}
}
free(loc_Vx);
}
MPI_Comm_free(&cartComm);
MPI_Comm_free(&colComm);
MPI_Comm_free(&rowComm);
MPI_Finalize();
}
| {
"alphanum_fraction": 0.5283432328,
"avg_line_length": 38.5355555556,
"ext": "c",
"hexsha": "de5246fb00d2c3b72dd521166158eb329fe7300d",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "d2fe69b49a6c13ccfb8404bce3d161cf0043d599",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "baishuai/MEXP",
"max_forks_repo_path": "mpi/mpi_all.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d2fe69b49a6c13ccfb8404bce3d161cf0043d599",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "baishuai/MEXP",
"max_issues_repo_path": "mpi/mpi_all.c",
"max_line_length": 119,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d2fe69b49a6c13ccfb8404bce3d161cf0043d599",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "baishuai/MEXP",
"max_stars_repo_path": "mpi/mpi_all.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4654,
"size": 17341
} |
#pragma once
#include "RTTI.h"
#include <d3d11.h>
#include <stack>
#include <gsl\gsl>
#include <vector>
namespace Library
{
class RenderTarget : public RTTI
{
RTTI_DECLARATIONS(RenderTarget, RTTI)
public:
RenderTarget() = default;
RenderTarget(const RenderTarget&) = delete;
RenderTarget(RenderTarget&&) = default;
RenderTarget& operator=(const RenderTarget&) = delete;
RenderTarget& operator=(RenderTarget&&) = default;
virtual ~RenderTarget() = default;
virtual void Begin() = 0;
virtual void End() = 0;
protected:
struct RenderTargetData
{
uint32_t ViewCount() const { return gsl::narrow_cast<uint32_t>(RenderTargetViews.size()); }
std::vector<ID3D11RenderTargetView*> RenderTargetViews;
gsl::not_null<ID3D11DepthStencilView*> DepthStencilView;
D3D11_VIEWPORT Viewport;
RenderTargetData(const gsl::span<ID3D11RenderTargetView*>& renderTargetViews, gsl::not_null<ID3D11DepthStencilView*> depthStencilView, const D3D11_VIEWPORT& viewport) :
RenderTargetViews(renderTargetViews.begin(), renderTargetViews.end()), DepthStencilView(depthStencilView), Viewport(viewport) { }
};
void Begin(gsl::not_null<ID3D11DeviceContext*> deviceContext, const gsl::span<ID3D11RenderTargetView*>& renderTargetViews, gsl::not_null<ID3D11DepthStencilView*> depthStencilView, const D3D11_VIEWPORT& viewport);
void End(gsl::not_null<ID3D11DeviceContext*> deviceContext);
void RebindCurrentRenderTargets(gsl::not_null<ID3D11DeviceContext*> deviceContext);
private:
static std::stack<RenderTargetData> sRenderTargetStack;
};
} | {
"alphanum_fraction": 0.7694267516,
"avg_line_length": 34.1304347826,
"ext": "h",
"hexsha": "942d41873fa296c37135a2455b5c5243edcf8ffe",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "05a05c5c26784dafa9a89747276f385252951f2f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ssshammi/real-time-3d-rendering-with-directx-and-hlsl",
"max_forks_repo_path": "source/Library.Shared/RenderTarget.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05a05c5c26784dafa9a89747276f385252951f2f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ssshammi/real-time-3d-rendering-with-directx-and-hlsl",
"max_issues_repo_path": "source/Library.Shared/RenderTarget.h",
"max_line_length": 214,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "05a05c5c26784dafa9a89747276f385252951f2f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ssshammi/real-time-3d-rendering-with-directx-and-hlsl",
"max_stars_repo_path": "source/Library.Shared/RenderTarget.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 412,
"size": 1570
} |
/*
* -----------------------------------------------------------------
* In Situ Adaptive Tabulation Library --- isat_lib.c
* Version: 1.6180
* Date: Nov 15, 2010
* -----------------------------------------------------------------
* Programmer: Americo Barbosa da Cunha Junior
* americo.cunhajr@gmail.com
* -----------------------------------------------------------------
* Copyright (c) 2010 by Americo Barbosa da Cunha Junior
*
* 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 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 General Public License for more details.
*
* A copy of the GNU General Public License is available in
* LICENSE.txt or http://www.gnu.org/licenses/.
* -----------------------------------------------------------------
* This is the implementation file of a library
* to work with ISAT algorithm.
* -----------------------------------------------------------------
*/
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include "../include/thrm_lib.h"
#include "../include/ell_lib.h"
#include "../include/ode_lib.h"
#include "../include/isat_lib.h"
/*
*------------------------------------------------------------
* isat_alloc
*
* This function alocates memory for a struct isat.
*
* Output:
* isat - pointer to a struct isat
*
* last update: Jul 13, 2010
*------------------------------------------------------------
*/
isat_wrk *isat_alloc()
{
/* memory allocation for isat_wrk */
isat_wrk *isat = NULL;
isat = (isat_wrk *) malloc(sizeof(isat_wrk));
if ( isat == NULL )
return NULL;
/* setting isat_wrk elements equal NULL and 0.0 */
isat->root = NULL;
isat->lf = 0;
isat->nd = 0;
isat->add = 0;
isat->grw = 0;
isat->rtv = 0;
isat->dev = 0;
isat->hgt = 0;
isat->max_lf = 0;
isat->time_add = 0.0;
isat->time_grw = 0.0;
isat->time_rtv = 0.0;
isat->time_dev = 0.0;
return isat;
}
/*------------------------------------------------------------*/
/*
*------------------------------------------------------------
* isat_free
*
* This function frees the memory used by a struct isat.
*
* Input:
* isat - pointer to a struct isat
*
* last update: May 10, 2009
*------------------------------------------------------------
*/
void isat_free(void **isat_bl)
{
isat_wrk *isat = NULL;
/* checking if isat_bl is NULL */
if ( *isat_bl == NULL )
return;
isat = (isat_wrk *) (*isat_bl);
/* releasing allocated memory by isat_wrk elements */
if( isat->root != NULL )
{
bst_node_free((void **)&(isat->root));
isat->root = NULL;
}
/* releasing allocated memory by isat_wrk */
free(*isat_bl);
*isat_bl = NULL;
return;
}
/*------------------------------------------------------------*/
/*
*------------------------------------------------------------
* isat_set
*
* This function initiates ISAT binary search tree.
*
* Input:
* isat - pointer to a struct isat
*
* last update: May 13, 2009
*------------------------------------------------------------
*/
int isat_set(isat_wrk *isat)
{
/* checking if isat is NULL */
if ( isat == NULL )
return GSL_EINVAL;
/* memory allocation for binary search tree root */
if ( isat->root == NULL )
{
isat->root = bst_node_alloc();
if ( isat->root == NULL )
{
free(isat);
isat = NULL;
return GSL_EINVAL;
}
}
return GSL_SUCCESS;
}
/*------------------------------------------------------------*/
/*
*------------------------------------------------------------
* isat_statistics
*
* This function prints on the screen informations
* about the isat workspace.
*
* Input:
* isat - pointer to a struct isat
*
* last update: Jul 13, 2010
*------------------------------------------------------------
*/
void isat_statistics(isat_wrk *isat)
{
double time_add;
double time_grw;
double time_rtv;
double time_dev;
time_add = (double) (isat->time_add / CLOCKS_PER_SEC) / isat->add;
time_grw = (double) (isat->time_grw / CLOCKS_PER_SEC) / isat->grw;
time_rtv = (double) (isat->time_rtv / CLOCKS_PER_SEC) / isat->rtv;
time_dev = (double) (isat->time_dev / CLOCKS_PER_SEC) / isat->dev;
printf("\n ISAT statistics:");
printf("\n # of adds = %d", isat->add);
printf("\n # of grows = %d", isat->grw);
printf("\n # of retrieves = %d", isat->rtv);
printf("\n # of dir. eval. = %d", isat->dev);
printf("\n # of leaves = %d", isat->lf);
printf("\n # of nodes = %d", isat->nd);
printf("\n tree height = %d\n", isat->hgt);
printf("\n average values for CPU time (s):");
printf("\n add: %+.6e",time_add);
printf("\n grw: %+.6e",time_grw);
printf("\n rtv: %+.6e",time_rtv);
printf("\n dev: %+.6e",time_dev);
return;
}
/*------------------------------------------------------------*/
/*
* -----------------------------------------------------------------
* isat_input
*
* This function receives ISAT parameters.
*
* Input:
* max_lf - maximum value of tree leaves
* etol - ISAT error tolerance
* n0 - factor to multiply by unit roundoff
*
* Output:
* success or error
*
* last update: Feb 25, 2010
* -----------------------------------------------------------------
*/
int isat_input(unsigned int *max_lf,double *etol,double *n0)
{
printf("\n Input ISAT parameters:\n");
printf("\n maximum of tree leaves:");
scanf("%d", max_lf);
printf("\n %d\n", *max_lf);
if( *max_lf <= 0 )
GSL_ERROR(" max_lf must be a positive integer (max_lf > 0)",GSL_EINVAL);
printf("\n ISAT error tolerance:");
scanf("%lf", etol);
printf("\n %+.1e\n", *etol);
if( *etol < 0.0 )
GSL_ERROR(" etol must be grather than zero (etol > 0.0)",GSL_EINVAL);
printf("\n Unit roundoff multiple:");
scanf("%lf", n0);
printf("\n %+.1e\n", *n0);
if( *n0 < 0.0 )
GSL_ERROR(" n0 must be grather than zero (n0 > 0.0)",GSL_EINVAL);
return GSL_SUCCESS;
}
/*----------------------------------------------------------------*/
/*
*------------------------------------------------------------
* isat_eoa_matrix
*
* This function computes the EOA matrix in Cholesky form.
*
* Input:
* A - gradient matrix
* n0 - factor to multiply by unit roundoff
* etol - error tolerance
*
* Output:
* L - EOA Cholesky matrix
*
* last update: Feb 19, 2010
*------------------------------------------------------------
*/
void isat_eoa_mtrx(gsl_matrix *A,double etol,double n0,
gsl_matrix *L)
{
unsigned int i;
double eps_max = 0.5;
double eps_min = etol/(n0*DBL_EPSILON);
gsl_matrix *Aetol = NULL;
gsl_matrix *V = NULL;
gsl_vector *sig = NULL;
/* memory allocation */
Aetol = gsl_matrix_calloc(A->size2,A->size2);
V = gsl_matrix_calloc(A->size2,A->size2);
sig = gsl_vector_calloc(A->size2);
/* Aetol := A */
gsl_matrix_memcpy(Aetol,A);
/* Aetol := (1/etol).A */
gsl_matrix_scale (Aetol,1.0/etol);
/* Aetol = U*sig*V^T */
ell_psd2eig(Aetol,V,sig);
/* eliminating small and large singular values */
for ( i = 0; i < sig->size; i++ )
sig->data[i] = GSL_MIN( GSL_MAX(sig->data[i],eps_max), eps_min);
/* V*sig^2*V^T = L*L^T */
ell_eig2chol(V,sig,L);
/* releasing allocated memory */
gsl_vector_free(sig);
gsl_matrix_free(V);
gsl_matrix_free(Aetol);
sig = NULL;
V = NULL;
Aetol = NULL;
return;
}
/*------------------------------------------------------------*/
/*
*------------------------------------------------------------
* isat_lerror
*
* This function computes the local error defined as
*
* eps = 2-norm(Rl(phi)- R(phi)) where
*
* Rl(phi) = R(phi0) + A*(phi-phi0).
*
* Input:
* Rphi - reaction mapping of phi
* Rphi0 - reaction mapping of phi0
* A - mapping gradient matrix
* phi - query composition
* phi0 - initial composition
*
* Output:
* eps - local error
*
* last update: Feb 19, 2010
*------------------------------------------------------------
*/
double isat_lerror(gsl_vector *Rphi,gsl_vector *Rphi0,
gsl_matrix *A,gsl_vector *phi,gsl_vector *phi0)
{
double eps;
gsl_vector *Rlphi = NULL;
/* memory allocation for Rlphi */
Rlphi = gsl_vector_calloc(phi->size);
/* Rlphi := R(phi0) + A*(phi-phi0) */
linear_approx(phi,phi0,Rphi0,A,Rlphi);
/* Rlphi := Rl(phi) - R(phi) */
gsl_vector_sub(Rlphi,Rphi);
/* eps := 2-norm(Rl(phi) - R(phi)) */
eps = gsl_blas_dnrm2(Rlphi);
/* releasing allocated memory */
gsl_vector_free(Rlphi);
Rlphi = NULL;
return eps;
}
/*------------------------------------------------------------*/
/*
*------------------------------------------------------------
* isat4
*
* This function executes the 4-th version of the
* in situ adaptive tabulation algorithm.
*
*
* Input:
* isat - isat workspace
* thrm_data - thermochemistry workspace
* etol - error tolerance
* n0 - factor to multiply by unit roundoff
* t0 - initial time
* delta_t - time step
* phi - query composition
* A - mapping gradient matrix
* L - EOA Cholesky matrix
*
* Output:
* Rphi - reaction mapping
* success or error
*
* last update: Nov 15, 2010
*------------------------------------------------------------
*/
int isat4(isat_wrk *isat,void *thrm_data,void *cvode_mem,
double etol,double n0,double t0,double delta_t,
gsl_vector *phi,gsl_matrix *A,gsl_matrix *L,gsl_vector *Rphi)
{
clock_t cpu_start = clock();
/* ISAT first step */
if( isat->lf == 0 )
{
int flag;
bst_leaf *first_leaf = NULL;
/* memory allocation for first_leaf */
first_leaf = bst_leaf_alloc();
if ( first_leaf == NULL )
return GSL_ENOMEM;
/* performing direct integration */
flag = odesolver_reinit(thrm_eqs,thrm_data,t0,
ATOL,RTOL,phi,cvode_mem);
if ( flag != GSL_SUCCESS )
return flag;
flag = odesolver(cvode_mem,delta_t,Rphi);
if ( flag != GSL_SUCCESS )
return flag;
/* computing the mapping gradient matrix */
flag = gradient(thrm_eqs,thrm_data,cvode_mem,t0,delta_t,
ATOL,RTOL,phi,Rphi,A);
if ( flag != GSL_SUCCESS )
return flag;
/* computing EOA Cholesky matrix */
isat_eoa_mtrx(A,etol,n0,L);
/* setting first leaf elements */
bst_leaf_set(phi,Rphi,A,L,first_leaf);
isat->root->r_leaf = first_leaf;
/* updating leaves and height counters */
isat->lf++;
isat->hgt = bst_height(isat->root);
return GSL_SUCCESS;
}
/* ISAT second and following steps */
int side, flag;
double dot = 0.0;
bst_leaf *end_leaf = NULL;
bst_node *end_node = NULL;
/* searching for the near composition in binary search tree */
if( isat->lf > 1 )
side = bst_search(isat->root,phi,&end_node,&end_leaf);
else
{
end_node = isat->root;
end_leaf = isat->root->r_leaf;
side = RIGHT;
}
/* checking if the near composition is inside EOA */
dot = ell_pt_in(phi,end_leaf->phi,end_leaf->L);
if( gsl_fcmp(dot,1.0,ATOL) < 1 )
{
/* computing linear approximation */
linear_approx(phi,end_leaf->phi,end_leaf->Rphi,end_leaf->A,Rphi);
/* updating counters */
isat->rtv++;
isat->time_rtv += clock() - cpu_start;
return GSL_SUCCESS;
}
else
{
double lerror = 0.0;
/* performing direct integration */
flag = odesolver_reinit(thrm_eqs,thrm_data,t0,
ATOL,RTOL,phi,cvode_mem);
if ( flag != GSL_SUCCESS )
return flag;
flag = odesolver(cvode_mem,delta_t,Rphi);
if ( flag != GSL_SUCCESS )
return flag;
/* computing ISAT local error */
lerror = isat_lerror(Rphi,end_leaf->Rphi,
end_leaf->A,phi,end_leaf->phi);
/* checking if lerror is greater than etol */
if( gsl_fcmp(lerror,etol,ATOL) < 1 )
{
/* growing the EOA */
ell_pt_modify(phi,end_leaf->phi,end_leaf->L);
/* updating counters */
isat->grw++;
isat->time_grw += clock() - cpu_start;
return GSL_SUCCESS;
}
else
{
/* checking if the maximum # of leaves was excced */
if( isat->lf > isat->max_lf )
{
/* updating counter */
isat->dev++;
isat->time_dev += clock() - cpu_start;
return GSL_SUCCESS;
}
bst_leaf *new_leaf = NULL;
/* memory allocation */
new_leaf = bst_leaf_alloc();
if ( new_leaf == NULL )
return GSL_ENOMEM;
/* computing the mapping gradient matrix */
flag = gradient(thrm_eqs,thrm_data,cvode_mem,t0,delta_t,
ATOL,RTOL,phi,Rphi,A);
if ( flag != GSL_SUCCESS )
return flag;
/* computing EOA Cholesky matrix */
isat_eoa_mtrx(A,etol,n0,L);
/* setting new_leaf elements */
bst_leaf_set(phi,Rphi,A,L,new_leaf);
/* cheking if binary search tree has more than one leaf */
if( isat->lf > 1 )
{
bst_node *new_node = NULL;
/* memory allocation for new node */
new_node = bst_node_alloc();
if ( new_node == NULL )
return GSL_ENOMEM;
/* setting the leaves of the new node */
bst_node_set(end_leaf,new_leaf,new_node);
/* adding the new node to the tree */
bst_node_add(side,end_node,new_node);
}
else
bst_node_set(end_leaf,new_leaf,end_node);
/* updating counters */
isat->add++;
isat->lf++;
isat->nd++;
isat->hgt = bst_height(isat->root);
isat->time_add += clock() - cpu_start;
return GSL_SUCCESS;
}
}
}
/*------------------------------------------------------------*/
| {
"alphanum_fraction": 0.4877330716,
"avg_line_length": 26.3989637306,
"ext": "c",
"hexsha": "7449bade9589b495b01864a58239d732efc987f0",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-12-30T01:44:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-15T03:57:44.000Z",
"max_forks_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "americocunhajr/CRFlowLib",
"max_forks_repo_path": "CRFlowLib-1.0/src/isat_lib.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "americocunhajr/CRFlowLib",
"max_issues_repo_path": "CRFlowLib-1.0/src/isat_lib.c",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "americocunhajr/CRFlowLib",
"max_stars_repo_path": "CRFlowLib-1.0/src/isat_lib.c",
"max_stars_repo_stars_event_max_datetime": "2020-12-29T12:56:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-29T12:56:14.000Z",
"num_tokens": 3945,
"size": 15285
} |
/*
* -----------------------------------------------------------------
* util_lib.h
* Utilities Library
* Version: 2.0
* Last Update: Nov 3, 2019
*
* Programmer: Americo Barbosa da Cunha Junior
* americo.cunhajr@gmail.com
* -----------------------------------------------------------------
* Copyright (c) 2010-2019, Americo Barbosa da Cunha Junior
* All rights reserved.
* -----------------------------------------------------------------
* This is the header file for UTIL_LIB module, a computational
* library with routines for miscelaneous applications.
* -----------------------------------------------------------------
*/
#ifndef __UTIL_LIB_H__
#define __UTIL_LIB_H__
#include <time.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_rng.h>
/*
*------------------------------------------------------------
* function prototypes
*------------------------------------------------------------
*/
int gsl_fprint_vector(FILE* file,
gsl_vector *v);
int gsl_print_vector(gsl_vector *v);
int gsl_print_matrix_line(unsigned int i,
gsl_matrix *M);
int gsl_print_matrix_column(unsigned int j,
gsl_matrix *M);
int gsl_print_matrix(gsl_matrix *M);
int gsl_rand_vector(gsl_rng *r,
gsl_vector *v);
int gsl_rand_matrix(gsl_rng *r,
gsl_matrix *M);
int gsl_diagonal_matrix(gsl_vector *v,
gsl_matrix *D);
void util_time_used(clock_t cpu_start,
clock_t cpu_end,
time_t wall_start,
time_t wall_end);
#endif /* __UTIL_LIB_H__ */
| {
"alphanum_fraction": 0.4806892454,
"avg_line_length": 24.3913043478,
"ext": "h",
"hexsha": "d4fc765db5925431057c673b7dba6702ac72bab8",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-12-30T01:44:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-15T03:57:44.000Z",
"max_forks_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "americocunhajr/CRFlowLib",
"max_forks_repo_path": "CRFlowLib-2.0/include/util_lib.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "americocunhajr/CRFlowLib",
"max_issues_repo_path": "CRFlowLib-2.0/include/util_lib.h",
"max_line_length": 67,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "35b67f798c1c33118c028691f42b98ba06220eeb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "americocunhajr/CRFlowLib",
"max_stars_repo_path": "CRFlowLib-2.0/include/util_lib.h",
"max_stars_repo_stars_event_max_datetime": "2020-12-29T12:56:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-29T12:56:14.000Z",
"num_tokens": 336,
"size": 1683
} |
#define _BSD_SOURCE
#include <bcm2835.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <math.h>
#include "csvparser.h"
#include <time.h>
#include "mailbox.h"
#include "gpu_fft.h"
#include "spi.h"
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_complex_math.h>
gsl_matrix_complex *compute_fft(int *points, int length) { //length should be specified as length = log2(FFT_length)
unsigned t[2];
struct GPU_FFT_COMPLEX *dataIn,*dataOut;
struct GPU_FFT *fftinfo;
int mb = mbox_open();
gpu_fft_prepare(mb,length,GPU_FFT_FWD,1,&fftinfo);
dataIn = fftinfo->in;
dataOut = fftinfo->out;
// Fill the fft data input array with signal
int i;
int FFT_length = 1 << length;
for (i = 0; i < FFT_length; i++) {
dataIn[i].re = points[i];
dataIn[i].im = 0;
}
usleep(1); // Yield to OS
clock_t t1 = clock();
gpu_fft_execute(fftinfo);
clock_t t2 = clock();
float diff = (1000000*(float)(t2 - t1) / CLOCKS_PER_SEC );
printf("Computed FFT of length %d in %f microseconds\n",FFT_length,diff);
gsl_matrix_complex *matrix = gsl_matrix_complex_alloc(FFT_length,1); //Initialize complex fft vector
// Fill it with complex values
for (i = 0; i < FFT_length; i++) {
gsl_complex complex = gsl_complex_rect(dataOut[i].re,dataOut[i].im);
gsl_matrix_complex_set(matrix, i, 0,complex); //Fill matrix rows
}
gpu_fft_release(fftinfo);
return matrix;
}
/*
scale_matrix function
matrix - comlex fft matrix to scale
This function scales matrix by it's size.
I use it to normalize fft vector.
*/
void scale_matrix(gsl_matrix_complex *matrix) {
size_t size = matrix->size1;
double scale = 1.0/size;
gsl_complex complex_scale = gsl_complex_rect(scale,0); // This is just a scale represented by a complex number
gsl_matrix_complex_scale(matrix,complex_scale); //Scale matrix by the length of the signal
}
/*
abs_matrix function
matrix - comlex fft matrix
This function takes an absolute valus of the complex matrix and returns a real matrix as a result.
*/
gsl_matrix *abs_matrix(gsl_matrix_complex *matrix) {
size_t size = matrix->size1;
gsl_matrix *absolute = gsl_matrix_alloc(size,1);
for (int i = 0; i < size; i++) {
gsl_complex complex = gsl_matrix_complex_get(matrix,i,0);
double abs = gsl_complex_abs(complex);
gsl_matrix_set(absolute,i,0,abs);
}
return absolute;
}
/*
half_matrix function
matrix - real values matrix
This function "chops" matrix in half to get the positive frequency spectrum.
*/
gsl_matrix *half_matrix(gsl_matrix *matrix) {
size_t size = matrix->size1;
size_t half_size = (size / 2)+1;
gsl_matrix *half = gsl_matrix_alloc(half_size,1); //Take only half of the absolute of ff
for (int i = 0; i < half_size; i++) {
double value = gsl_matrix_get(matrix,i,0);
gsl_matrix_set(half,i,0,value);
}
return half;
}
/*
save_waveform_to_file function
data - signal
length - signal length
filename - name of the file to be saved to
Saves the signal to the file.
*/
void save_waveform_to_file(int *data, int length, char *filename) {
FILE *f = fopen(filename,"w");
printf("Length: %d\n",length);
for (int i = 0; i < length; i++) {
fprintf(f,"%d,\n",data[i]);
}
fclose(f);
}
/*
print_result_to_file function
result - vector
filename - name of the file to be saved to
Saves the vector to the file.
*/
void print_result_to_file(gsl_matrix *result, char *filename) {
FILE *f = fopen(filename,"w");
int size = result->size1;
for (int i = 0; i < size; i++) {
double value = gsl_matrix_get(result,i,0);
fprintf(f,"%d,\n",value);
}
fclose(f);
}
/*
print_fft_to_file function
result - complex fft vector
Saves the vector to the file.
*/
void print_fft_to_file(gsl_matrix_complex *result) {
FILE *real = fopen("real.csv","w");
FILE *imag = fopen("imag.csv","w");
int size = result->size1;
for (int i = 0; i < size; i++) {
gsl_complex value = gsl_matrix_complex_get(result,i,0);
fprintf(real,"%f,\n",value.dat[0]);
fprintf(imag,"%f,\n",value.dat[1]);
}
fclose(real);
fclose(imag);
}
void display_harmonics(gsl_matrix *fft_vector) {
double value_60 = gsl_matrix_get(fft_vector,60,0);
double amplitude = value_60 * (3.72/4096);
printf("Amplitude of 60Hz is: %f\n",amplitude);
}
/*
extract_50_harmonics function
fft_vector - complex fft vector
Exracts 50 fundamental hormonics
60,120,180, etc
Returns the harmonics array of size 50.
*/
int *extract_50_harmonics(gsl_matrix *fft_vector) {
int *harmonics = (int *)malloc(sizeof(int)*50);;
for (int i = 1; i < 51; i++) {
double value = gsl_matrix_get(fft_vector,i*60,0);
int amplitude = (int)(value * (1000.0/4096) / 1.14);
harmonics[i-1] = amplitude;
}
return harmonics;
}
/*
perform_fft_analysis function
points - signal
performs fft analysis
*/
void perform_fft_analysis(int *points) {
clock_t t1 = clock();
int length = 1 << WINDOW_SIZE; // Sampling frequency
gsl_matrix_complex *fft_matrix = compute_fft(points,WINDOW_SIZE); // performs fft transformation of the signal
scale_matrix(fft_matrix); // normalizes the resulting fft vector
gsl_matrix *absolute = abs_matrix(fft_matrix); // takes an absolute value of the fft vector
gsl_matrix *half = half_matrix(absolute); // and chops of the negative part.
gsl_matrix_scale(half,2); // Scales by two
clock_t t2 = clock();
float diff = ((float)(t2 - t1) / CLOCKS_PER_SEC );
printf("FFT analysis took: %f seconds\n",diff);
int *harmonics = extract_50_harmonics(half); // extracts harmonics
for (int i = 1; i < 51; i++) { // diplays harmonics aplitudes.
printf("Amplitude at %d Hz is %d mV\n",i*60,harmonics[i-1]);
}
// frees the resources.
gsl_matrix_free(half);
gsl_matrix_free(absolute);
gsl_matrix_complex_free(fft_matrix);
free(harmonics);
}
/*
rms function
signal - signal
frequency - signal frequency
Computes rms value of the given signal.
*/
int rms(int *signal, int frequency) {
clock_t t1 = clock();
int sum = 0;
for (int i = 0; i < frequency; i++) {
int data = signal[i];
sum += data*data;
}
sum /= frequency;
double root = sqrt((double)sum);
clock_t t2 = clock();
float diff = ((float)(t2 - t1) / CLOCKS_PER_SEC );
printf("RMS analysis took: %f seconds\n",diff);
printf("RMS value: %f\n",root);
return (int)root;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("Usage %s channel\n",argv[0]);
return 1;
}
int channels[8] = {0};
// Extract which channels to sample from the command arguments.
for (int arg_index = 0; arg_index < argc - 1; arg_index++) {
int channel = atoi(argv[arg_index + 1]);
printf("Sampling channel %d\n",channel);
channels[channel] = 1;
}
if (init()) {
printf("Init failed.\n");
return 1;
} else {
printf("Succesfull init of bcm2835.\n");
}
printf("Starting bcm2835 setup...\n");
setup();
printf("bcm2835 setup finished.\n");
for (int i = 0; i < 1; i++) { // Specify sampling duration here! If we want to sample indefinetely, just write while(1) {}
int frequency = 1 << WINDOW_SIZE;
sample *s = sample_data(channels,frequency);
perform_fft_analysis(s->channel_data[1]);
sample_deallocate(s);
}
printf("Ending spi connection ...\n");
end();
printf("bcm2835 has ended.\n");
}
| {
"alphanum_fraction": 0.658184228,
"avg_line_length": 26.9464285714,
"ext": "c",
"hexsha": "964c2509fd0872323c900c17258e8cd760a5d5c8",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "039e3ac56aa8ae9c59fe75c571ff473e9d112d2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seadsystem/FFT-Harmonic-Extraction",
"max_forks_repo_path": "fft/hello_fft.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "039e3ac56aa8ae9c59fe75c571ff473e9d112d2a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seadsystem/FFT-Harmonic-Extraction",
"max_issues_repo_path": "fft/hello_fft.c",
"max_line_length": 126,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "039e3ac56aa8ae9c59fe75c571ff473e9d112d2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "seadsystem/FFT-Harmonic-Extraction",
"max_stars_repo_path": "fft/hello_fft.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2105,
"size": 7545
} |
#ifndef FUSED_LASSO_E_H
#define FUSED_LASSO_E_H
#include "Matrix.h"
#include "LADMM.h"
#include <string>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <stdio.h> /* printf */
#include <time.h>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <ctime>
#include <math.h>
//This class solves problem: min_x f(x)+ g(x)+ h(Mx) by LADMM;
// where g(x)=\frac{lambda2}{2}\|x\|_2^2 +lambda1\|x\|_1;
// f(x)= 1/2*\|Ax- b\|_2^2= \sum_i phi_i(A_ix);
// f_i(x)= 0.5*(x- b_i)^2, h_i(x)= \|x\|, Mx= (x^1- x^2, ..., x_n- x_1).
template<typename L, typename D>
class Fused_lasso_e: public LADMM<L, D>
{
private:
D lambda1;
D lambda2;
D lambda3;
Matrix<L,D> my_M;
Matrix<L,D> my_A;
protected:
public:
Fused_lasso_e(const char* Matrix_file,const char* Matrix_file2, D val_lambda1, D val_lambda2, D val_lambda3)
:LADMM<L,D>(),my_A(Matrix_file), my_M(Matrix_file2)
{
lambda1=val_lambda1;
lambda2=val_lambda2;
lambda3=val_lambda3;
this->lambda_f= 1;
}
Fused_lasso_e(const char* Matrix_file,D val_lambda1, D val_lambda2, D val_lambda3)
:LADMM<L,D>(),my_A(Matrix_file)
{
lambda1=val_lambda1;
lambda2=val_lambda2;
lambda3=val_lambda3;
this->lambda_f= 1;
my_M.construct_fused_matrix(my_A);
}
L get_n(){return my_M.nfeatures;}
L get_m(){return my_M.nsamples;}
inline D gradient_of_f_j(D x1, L i){
return x1- my_A.b[i];
}
inline D value_of_g_j(D x, L i){
return lambda2*x*x/2+lambda1*fabs(x);
}
inline D value_of_f_j(D x1, L i){
return 0.5*(x1- my_A.b[i])*(x1- my_A.b[i]);
}
inline D value_of_h_j(D x, L i){
return lambda3*fabs(x);
}
inline D prox_of_h_j(D x1,D x2, L i){
D newx;
if (x1- lambda3/x2> my_M.b[i]){
newx= x1- lambda3/x2;
}
else if(x1+ lambda3/x2< my_M.b[i]){
newx= x1+ lambda3/x2;
}
else{
newx= my_M.b[i];
}
return newx;
}
inline D prox_of_g_j(D x1,D x2, L i){
D new_x;
if(x1*x2> lambda1)
new_x=(x1*x2- lambda1)/(x2+lambda2);
else if(x1*x2< -lambda1)
new_x=(x1*x2+ lambda1)/(x2+ lambda2);
else
new_x=0;
return new_x;
}
inline void set_matrix_M(){
this->data_M=my_M;
}
inline void set_matrix_A(){
this->data_A=my_A;
}
/*
inline void set_matrix_A(){
this->data_A.nsamples=0;
this->data_A.nfeatures=this->data_M.nfeatures;
this->data_A.nnz=0;
this->data_A.ptr.resize(1,0);
this->data_A.ptr_t.resize(this->data_M.nfeatures+1,0);
}
*/
void LADMM_solver(D beta_0, D rho,vector<D> & x0,vector<D> & y0, vector<D> & lambda0, L max_nb_outer, L p_N_1, string filename1, D time){
this->ADMM_solve_with_Linear(beta_0, rho,x0,y0, lambda0, max_nb_outer, p_N_1, filename1, time);
}
};
#endif
| {
"alphanum_fraction": 0.623533594,
"avg_line_length": 19.0067567568,
"ext": "h",
"hexsha": "6db69c095f204c39b567bd8193ebfc5f2e3a5312",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-15T04:23:24.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-15T04:23:24.000Z",
"max_forks_repo_head_hexsha": "3d5d8c281411fdfd6379480429a1fbb9b21464ff",
"max_forks_repo_licenses": [
"BSD-Source-Code"
],
"max_forks_repo_name": "lifei16/supplementary_code",
"max_forks_repo_path": "IPALM_OPENMP/Fused_lasso_e.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3d5d8c281411fdfd6379480429a1fbb9b21464ff",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-Source-Code"
],
"max_issues_repo_name": "lifei16/supplementary_code",
"max_issues_repo_path": "IPALM_OPENMP/Fused_lasso_e.h",
"max_line_length": 140,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3d5d8c281411fdfd6379480429a1fbb9b21464ff",
"max_stars_repo_licenses": [
"BSD-Source-Code"
],
"max_stars_repo_name": "lifei16/supplementary_code",
"max_stars_repo_path": "IPALM_OPENMP/Fused_lasso_e.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 992,
"size": 2813
} |
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
#include <cblas.h>
/* Your function must have the following signature: */
void sgemm( int m, int n, float *A, float *C );
/* The benchmarking program */
int main( int argc, char **argv )
{
srand(time(NULL));
if(argc != 3)
{
printf("Incorrect number of arguments!\n");
printf("Usage: ./bench-test M N\n");
exit(0);
}
int m = atoi(argv[1]);
int n = atoi(argv[2]);
// Change these values to modify range checking
if(m < 1000 || m > 10000 || n < 32 || n > 10000)
{
printf("Dimensions provided are out of the range of matrices we will be testing! Change tester.c to modify range checking.\n");
exit(0);
}
/* Allocate and fill 2 random matrices A, C */
float *A = (float*) malloc( m * n * sizeof(float) );
float *C = (float*) malloc( m * m * sizeof(float) );
for( int i = 0; i < m*n; i++ ) A[i] = 2 * drand48() - 1;
for( int i = 0; i < m*m; i++ ) C[i] = 2 * drand48() - 1;
/* measure Gflop/s rate; time a sufficiently long sequence of calls to eliminate noise */
double Gflop_s, seconds = -1.0;
for( int n_iterations = 1; seconds < 0.1; n_iterations *= 2 )
{
/* warm-up */
sgemm( m, n, A, C );
/* measure time */
struct timeval start, end;
gettimeofday( &start, NULL );
for( int i = 0; i < n_iterations; i++ )
sgemm( m,n, A, C );
gettimeofday( &end, NULL );
seconds = (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec);
/* compute Gflop/s rate */
Gflop_s = 2e-9 * n_iterations * m * m * n / seconds;
}
printf( "%d by %d matrix \t %g Gflop/s\n", m, n, Gflop_s );
/* Ensure that error does not exceed the theoretical error bound */
/* Set initial C to 0 and do matrix multiply of A*B */
memset( C, 0, sizeof( float ) * m * m );
sgemm( m,n, A, C );
/* Subtract A*B from C using standard sgemm (note that this should be 0 to within machine roundoff) */
cblas_sgemm( CblasColMajor,CblasNoTrans,CblasTrans, m,m,n, -1, A,m, A,m, 1, C,m );
/* Subtract the maximum allowed roundoff from each element of C */
for( int i = 0; i < m*n; i++ ) A[i] = fabs( A[i] );
for( int i = 0; i < m*m; i++ ) C[i] = fabs( C[i] );
cblas_sgemm( CblasColMajor,CblasNoTrans,CblasTrans, m,m,n, -3.0*FLT_EPSILON*n, A,m, A,m, 1, C,m );
/* After this test if any element in C is still positive something went wrong in square_sgemm */
for( int i = 0; i < m * m; i++ )
if( C[i] > 0 ) {
printf( "FAILURE: error in matrix multiply exceeds an acceptable margin\n" );
return -1;
}
/* release memory */
free( C );
free( A );
return 0;
}
| {
"alphanum_fraction": 0.6070491189,
"avg_line_length": 29.3076923077,
"ext": "c",
"hexsha": "992ca03b508636d3ca3da57b0eaaf5d5dddde6bb",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4c3e75f48bdafa02fabb551beb6ebf2fea871238",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jasonaibrahim/AcademicWorks",
"max_forks_repo_path": "MatrixMultiply/tester.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4c3e75f48bdafa02fabb551beb6ebf2fea871238",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jasonaibrahim/AcademicWorks",
"max_issues_repo_path": "MatrixMultiply/tester.c",
"max_line_length": 130,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4c3e75f48bdafa02fabb551beb6ebf2fea871238",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jasonaibrahim/AcademicWorks",
"max_stars_repo_path": "MatrixMultiply/tester.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 892,
"size": 2667
} |
#include <math.h>
#include <stdio.h>
#include <mpfr.h>
#include <petsc.h>
#include <stdlib.h>
#include <string.h>
#include "ellipsoid/ellipsoid.h"
int testCoordinateTransform()
{
//Verify that the ellipsoidal to Cartesian transformation is a bijection
//the tolerance is 10 significant figures
EllipsoidalSystem e;
initEllipsoidalSystem(&e, 3.0, 2.0, 1.0, 32);
double relErrorX, relErrorY, relErrorZ;
//loop over octants
for(int sx=-1; sx<=1; sx+=2) { //sx = [-1,1]
for(int sy=-1; sy<=1; sy+=2) { //sy = [-1,1]
for(int sz=-1; sz<=1; sz+=2) { //sz = [-1,1]
//loop over brick in cartesian space
for(double x=4; x<5+tol; x+=1.5) {
for(double y=4; y<5+tol; y+=1.5) {
for(double z=4; z<5+tol; z+=1.5) {
Point temp = { .x1 = sx*x, .x2 = sy*y, .x3 = sz*z };
cartesianToEllipsoidal(&e, &temp);
ellipsoidToCartesian(&e, &temp);
relErrorX = fabs(sx*x - temp.x1)/x;
relErrorY = fabs(sy*y - temp.x2)/y;
relErrorZ = fabs(sz*z - temp.x3)/z;
//check error
if( relErrorX > tol ||
relErrorY > tol ||
relErrorZ > tol) {
printf("testCoordinateTransform failed\n");
printf("relative error(x): %16.16f\n", relErrorX);
printf("relative error(y): %16.16f\n", relErrorY);
printf("relative error(z): %16.16f\n", relErrorZ);
return 0;
}
}
}
}
}
}
}
return 1;
}
int testLameType()
{
static char formula1[18] = "K^0_1 L^0_1 M^0_1";
static char formula2[30] = "K^0_2 K^1_2 L^0_2 M^0_2 N^0_2";
static char formula3[66] = "K^0_5 K^1_5 K^2_5 L^0_5 L^1_5 L^2_5 M^0_5 M^1_5 M^2_5 N^0_5 N^1_5";
char **checks = (char**) malloc(sizeof(char*)*3);
checks[0] = (char*) malloc(sizeof(char)*17);
checks[1] = (char*) malloc(sizeof(char)*29);
checks[2] = (char*) malloc(sizeof(char)*65);
EllipsoidalSystem e;
initEllipsoidalSystem(&e, 3.0, 2.0, 1.0, 32);
int index[3] = { 1, 2, 5 };
int k;
int n;
for(int i=0; i<3; ++i) {
n = index[i];
for(int p=0; p < 2*n + 1; ++p) {
k = p*6;
checks[i][k] = getLameTypeT(n, p);
checks[i][k+1] = '^';
checks[i][k+2] = getLameTypeTp(n, p) + '0';
checks[i][k+3] = '_';
checks[i][k+4] = n + '0';
if( p != 2*n )
checks[i][k+5] = ' ';
}
}
//check first string
for(int i=0; i < 17; ++i) {
if(checks[0][i] != formula1[i]) {
return 0;
}
}
//check second string
for(int i=0; i < 29; ++i) {
if(checks[1][i] != formula2[i]) {
return 0;
}
}
//check first string
for(int i=0; i < 65; ++i) {
if(checks[2][i] != formula3[i]) {
return 0;
}
}
free(checks[0]);
free(checks[1]);
free(checks[2]);
free(checks);
return 1;
}
int testI()
{
//Using results from Dassios, test the computation of I^p_n for n = 0, 1, 2
EllipsoidalSystem e;
initEllipsoidalSystem(&e, 3.0, 2.0, 1.0, 32);
double a = e.a;
double b = e.b;
double c = e.c;
double h = e.h;
double k = e.k;
double l = a;
double rootSum = sqrt((a*a*a*a - b*b*c*c) + (b*b*b*b - a*a*c*c) + (c*c*c*c - a*a*b*b));
double DassiosLambda = (1/3.)*(a*a + b*b + c*c) + (1/3.)*rootSum;
double DassiosLambdaPrime = (1/3.)*(a*a + b*b + c*c) - (1/3.)*rootSum;
double errors[18];
int derror[18] = { 1, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13 };
int ecount = 0;
//Dassios D1 error
double lhs = 3 * (DassiosLambda + DassiosLambdaPrime);
double rhs = 2 * (a*a + b*b + c*c);
errors[ecount] = fabs(lhs - rhs); ecount++;
//Dassios D2 error
lhs = 3 * DassiosLambda * DassiosLambdaPrime;
rhs = a*a*b*b + a*a*c*c + b*b*c*c;
errors[ecount] = fabs(lhs - rhs); ecount ++;
//Dassios D3 error
lhs = ((-1)*(b*b - c*c)*(DassiosLambda - a*a)) + (k*k*(DassiosLambda - b*b)) + (-h*h*(DassiosLambda - c*c));
rhs = ((-1)*(b*b - c*c)*(DassiosLambdaPrime - a*a)) + (k*k*(DassiosLambdaPrime - b*b)) + (-h*h*(DassiosLambdaPrime - c*c));
errors[ecount] = fabs(lhs-0); ecount++;
errors[ecount ] = fabs(rhs-0); ecount++;
//Dassios D4 error
lhs = (-a*a*(b*b - c*c)*(DassiosLambda - a*a)) + (b*b*k*k*(DassiosLambda - b*b)) + (-c*c*h*h*(DassiosLambda - c*c));
rhs = (-a*a*(b*b - c*c)*(DassiosLambdaPrime - a*a)) + (b*b*k*k*(DassiosLambdaPrime - b*b)) + (-c*c*h*h*(DassiosLambdaPrime - c*c));
double analytical = h*h*k*k*(b*b - c*c);
errors[ecount] = fabs(lhs - analytical); ecount++;
errors[ecount] = fabs(rhs - analytical); ecount++;
//Dassios D5 error
double alpha[3] = { a, b, c };
lhs = 0;
rhs = 0;
for(int i=0; i<3; ++i) {
lhs += alpha[i]*alpha[i]/(alpha[i]*alpha[i] - DassiosLambda);
rhs += alpha[i]*alpha[i]/(alpha[i]*alpha[i] - DassiosLambdaPrime);
}
errors[ecount] = fabs(lhs - 3); ecount++;
errors[ecount] = fabs(rhs - 3); ecount++;
//Dassios D6 error
double anal1 = h*h*k*k*(b*b - c*c);
double num1 = 3*(b*b - c*c)*(DassiosLambda - a*a)*(DassiosLambdaPrime - a*a);
double anal2 = -h*h*k*k*(b*b - c*c);
double num2 = 3*k*k*(DassiosLambda - b*b)*(DassiosLambdaPrime - b*b);
double anal3 = h*h*k*k*(b*b - c*c);
double num3 = 3*h*h*(DassiosLambda - c*c)*(DassiosLambdaPrime - c*c);
errors[ecount] = fabs(num1 - anal1); ecount++;
errors[ecount] = fabs(num2 - anal2); ecount++;
errors[ecount] = fabs(num3 - anal3); ecount++;
//Calculate I^p_n
int nmax = 2;
int Isize = 0;
for(int n=0; n < nmax+1; ++n) {
for(int p=0; p < 2*n+1; ++p) {
Isize++;
}
}
double *Ival = (double*) malloc(sizeof(double)*Isize);
int i=0;
for(int n=0; n < nmax+1; ++n) {
for(int p=0; p < 2*n+1; ++p) {
calcI(&e, n, p, l, 1, 1, Ival+i); //Ival[i] = calcI(&e, n, p, l, 1, 1);
i++;
}
}
//Dassios D7: their h_3 = our h and their h_2 = our k
double analyticalSumTest1 = 1.0/(l*sqrt(l*l - h*h)*sqrt(l*l - k*k));
double numericalSumTest1 = 0;
for(int k=1; k<4; ++k) {
numericalSumTest1 += Ival[k];
}
errors[ecount] = fabs(analyticalSumTest1 - numericalSumTest1); ecount++;
//Dassios D8: their alpha1 = our a, their alpha2 = our b, their alpha3 = our c
double analyticalSumTest2 = Ival[0] - (l*l - a*a)/(l*sqrt(l*l - h*h)*sqrt(l*l - k*k));
double numericalSumTest2 = a*a*Ival[1] + b*b*Ival[2] + c*c*Ival[3];
errors[ecount] = fabs(analyticalSumTest2 - numericalSumTest2); ecount++;
//Dassios D9: their Lambda = our DassiosLambda, their LambdaPrime = our DassiosLambdaPrime
double analyticalSumTest3 = 1.0/(2.0*(DassiosLambda - a*a + l*l)*l*sqrt(l*l - h*h)*sqrt(l*l - k*k)) - (1.0/2.0)*(Ival[1]/(DassiosLambda - a*a) + Ival[2]/(DassiosLambda - b*b) + Ival[3]/(DassiosLambda - c*c));
double numericalSumTest3 = Ival[4];
errors[ecount] = fabs(analyticalSumTest3 - numericalSumTest3); ecount++;
//Dassios D10: their Lambda = our DassiosLambda, their LambdaPrime = our DassiosLambdaPrime
double analyticalSumTest4 = 1.0/(2.0*(DassiosLambdaPrime - a*a + l*l)*l*sqrt(l*l - h*h)*sqrt(l*l - k*k)) - (1.0/2.0)*(Ival[1]/(DassiosLambdaPrime - a*a) + Ival[2]/(DassiosLambdaPrime - b*b) + Ival[3]/(DassiosLambdaPrime - c*c));
double numericalSumTest4 = Ival[5];
errors[ecount] = fabs(analyticalSumTest4 - numericalSumTest4); ecount++;
//Dassios D11: their h1*h1 = our (b*b - c*c)
double analyticalSumTest5 = (1.0/(h*h)) * (Ival[2] - Ival[1]);
double numericalSumTest5 = Ival[6];
errors[ecount] = fabs(analyticalSumTest5 - numericalSumTest5); ecount++;
//Dassios D12: their h1*h1 = our (b*b - c*c)
double analyticalSumTest6 = (1.0/(k*k)) * (Ival[3] - Ival[1]);
double numericalSumTest6 = Ival[7];
errors[ecount] = fabs(analyticalSumTest6 - numericalSumTest6); ecount++;
//Dassios D13: their h1*h1 = our (b*b - c*c)
double analyticalSumTest7 = (1.0/(b*b - c*c)) * (Ival[3] - Ival[2]);
double numericalSumTest7 = Ival[8];
errors[ecount] = fabs(analyticalSumTest7 - numericalSumTest7); ecount++;
//checking errors
for(int i=0; i < 18; ++i) {
if(errors[i] > tol) {
printf("Dassios D%d failed with error %8.8e\n", derror[i], errors[i]);
free(Ival);
return 0;
}
}
free(Ival);
return 1;
}
int testNormalization()
{
//Check calculated \gamma^p_n against analytic results for n = 0, 1, 2
double a = 3.0;
double b = 2.0;
double c = 1.0;
EllipsoidalSystem e;
initEllipsoidalSystem(&e, a, b, c, 32);
//Dassios (B14)
double firstTerm = (a*a + b*b + c*c)/3.0;
double secondTerm = sqrt((a*a*a*a - b*b*c*c) + (b*b*b*b - a*a*c*c) + (c*c*c*c - a*a*b*b))/3.0;
double LambdaD = firstTerm + secondTerm;
double LambdaDprime = firstTerm - secondTerm;
//Dassios (B16)-(B20)
double hx = sqrt(b*b - c*c);
double hy = e.k;
double hz = e.h;
double analytic[9] = { 4*PETSC_PI,
4*PETSC_PI/3 * hy*hy*hz*hz,
4*PETSC_PI/3 * hx*hx*hz*hz,
4*PETSC_PI/3 * hx*hx*hy*hy,
-8*PETSC_PI/5 * (LambdaD - LambdaDprime)*(LambdaD - a*a)*(LambdaD - b*b)*(LambdaD - c*c),
8*PETSC_PI/5 * (LambdaD - LambdaDprime)*(LambdaDprime - a*a)*(LambdaDprime - b*b)*(LambdaDprime - c*c),
4*PETSC_PI/15 * hx*hx*hy*hy*hz*hz*hz*hz,
4*PETSC_PI/15 * hx*hx*hy*hy*hy*hy*hz*hz,
4*PETSC_PI/15 * hx*hx*hx*hx*hy*hy*hz*hz };
printf("analytic[0] = %4.4e\n", analytic[0]);
printf("analytic[1] = %4.4e\n", analytic[1]);
double value, estimate, error;
int counter = 0;
for(int n=0; n<3; ++n) {
for(int p=0; p<2*n+1; ++p) {
value = analytic[counter];
calcNormalization(&e, n, p, &estimate);
error = estimate - value;
if(fabs(error) > tol) {
printf("testnormalization failed iteration %d at (n,p) = (%d,%d) with error %8.8e\n", counter, n, p, fabs(error));
return 0;
}
counter++;
}
}
return 1;
}
void testfunc(mpfr_t *x, mpfr_t *val, FuncInfo4 *ctx)
{
double a2 = (*ctx).a2;
double b2 = (*ctx).b2;
double c2 = (*ctx).c2;
double botVar = (*ctx).botVar;
mpfr_t temp, s;
mpfr_init2(temp, mpfr_get_prec(*x));
mpfr_init2(s , mpfr_get_prec(*x));
//change of variables
//s = (1-x)/x
mpfr_d_sub(s, 1.0, *x, MPFR_RNDZ);
mpfr_div(s, s, *x, MPFR_RNDN);
mpfr_add_d(temp, s, a2, MPFR_RNDN);
mpfr_add_d(*val, s, b2, MPFR_RNDN);
mpfr_mul(*val, *val, temp, MPFR_RNDN);
mpfr_add_d(temp, s, c2, MPFR_RNDN);
mpfr_mul(*val, *val, temp, MPFR_RNDN);
mpfr_sqrt(*val, *val, MPFR_RNDN);
mpfr_add_d(temp, s, botVar, MPFR_RNDN);
mpfr_mul(*val, *val, temp, MPFR_RNDN);
mpfr_d_div(*val, 1.0, *val, MPFR_RNDN);
//multiply by dt = ds * (1+t)^2
mpfr_add_d(temp, s, 1.0, MPFR_RNDN);
mpfr_mul(temp, temp, temp, MPFR_RNDN);
mpfr_mul(*val, *val, temp, MPFR_RNDN);
//mpfr_clears(temp, s, NULL);
}
int testSurfaceOperatorEigenvalues()
{
EllipsoidalSystem e;
double a = 3.0;
double b = 2.0;
double c = 1.0;
initEllipsoidalSystem(&e, a, b, c, 32);
double l = a;
int n = 1;
double analytic[3];
mpfr_t integral;
mpfr_t mpfrzero, mpfrone;
mpfr_inits(mpfrzero, mpfrone, integral, NULL);
mpfr_set_d(mpfrzero, 0.0, MPFR_RNDN);
mpfr_set_d(mpfrone, 1.0, MPFR_RNDN);
//Integrals are from Ritter, need to transform integrals to finite interval
FuncInfo4 ctx = { &e, a*a, b*b, c*c, a*a };
integrateMPFR((PetscErrorCode (*)(mpfr_t*, mpfr_t*, void*)) testfunc, &e, mpfrzero, mpfrone, 14, &integral, &ctx);
analytic[0] = (a*b*c * mpfr_get_d(integral, MPFR_RNDN) - 1.0)/2.0;
ctx.botVar = b*b;
integrateMPFR((PetscErrorCode (*)(mpfr_t*, mpfr_t*, void*)) testfunc, &e, mpfrzero, mpfrone, 14, &integral, &ctx);
analytic[1] = (a*b*c * mpfr_get_d(integral, MPFR_RNDN) - 1.0)/2.0;
ctx.botVar = c*c;
integrateMPFR((PetscErrorCode (*)(mpfr_t*, mpfr_t*, void*)) testfunc, &e, mpfrzero, mpfrone, 14, &integral, &ctx);
analytic[2] = (a*b*c * mpfr_get_d(integral, MPFR_RNDN) - 1.0)/2.0;
double *ev = (double*) malloc(sizeof(double)*(3));
for(int p=0; p < 3; ++p)
calcSurfaceOperatorEigenvalues(&e, n, p, l, 1, 1, ev+p); //ev[p] = calcSurfaceOperatorEigenvalues(&e, n, p, l, 1, 1);
for(int p=0; p < 3; ++p) {
if(fabs(ev[p] - analytic[p]) > tol) {
printf("analytic (%8.8e) doesn't match numerical (%8.8e), error = (%8.8e) for integral %d\n", analytic[p], ev[p], fabs(ev[p] - analytic[p]), p+1);
return 0;
}
}
mpfr_clears(mpfrzero, mpfrone, integral, NULL);
free(ev);
return 1;
}
int compareIntegration()
{
//int n, p given in calcNormalization
int n = 1;
int p = 1;
int digits = 32;
//set up ellipsoidal system
EllipsoidalSystem e;
double xA = 3.0;
double yB = 2.0;
double zC = 1.0;
initEllipsoidalSystem(&e, xA, yB, zC, digits);
mpfr_t bound_a, bound_b;
mpfr_inits2(4*digits, bound_a, bound_b, NULL);
FuncInfo2 ctx1 = { .e = &e, .n = n, .p = p, .numeratorType = 0, .denomSign = 1 };
mpfr_t a, b, c;
mpfr_inits(a, b, c, NULL);
double integralMPFR, integralMidpoint;
integrateMPFR((PetscErrorCode (*)(mpfr_t*, mpfr_t*, void*)) normFunction1, &e, e.hp_h, e.hp_k, 14, &integralMPFR, &ctx1);
integrateMidpoint((PetscErrorCode (*)(mpfr_t*, mpfr_t*, void*)) normFunction1, e.hp_h, e.hp_k, 10, &integralMidpoint, &ctx1);
printf("MPFR integral is: %15.15f\n", integralMPFR);
printf("Midpoint integral is: %15.15f\n", integralMidpoint);
printf("oh wow\n");
mpfr_clears(a, b, c, NULL);
return 0;
}
int main(int argc, char **argv)
{
mpfr_set_default_prec(4*64);
/*
EllipsoidalSystem e;
initEllipsoidalSystem(&e, 3.0, 2.0, 1.0);
printf("h: %15.15f\nh2: %15.15f\nk: %15.15f\nk2: %15.15f\n", e.h, e.h2, e.k, e.k2);
int n = 1;
int p = 1;
double l = 1.0;
//printf("calcLame(1, 1, 1.0) = %15.15f\n", calcLame(&e, 1, 1, 1.0));
printf("calcNormalization(%d, %d, %15.15f) = %15.15f\n", n, p, l, calcNormalization(&e, n, p));
*/
if(testCoordinateTransform())
printf("testCoordinateTransform passed\n");
else
printf("testCoordinateTransform failed\n");
if(testLameType())
printf("testLameType passed\n");
else
printf("testLameType failed\n");
if(testI())
printf("testI passed\n");
else
printf("testI failed\n");
if(testNormalization())
printf("testNormalization passed\n");
else
printf("testNormalization failed\n");
if(testSurfaceOperatorEigenvalues())
printf("testSurfaceOperatorEigenvalues passed\n");
else
printf("testSurfaceOperatorEigenvalues failed\n");
//compareIntegration();
/*
double h = .1;
mpfr_t x, val;
EllipsoidalSystem e;
initEllipsoidalSystem(&e, 3.0, 2.0, 1.0);
FuncInfo2 ctx1 = { .e = &e, .n = 1, .p = 2, .numeratorType = 0, .denomSign = -1 };
mpfr_inits2(4*16, x, val, NULL);
for(int k=0; k < 10; ++k) {
mpfr_set_d(x, k*h, MPFR_RNDN);
normFunction1(&x, &val, &ctx1);
printf("normfunction1(%8.8f) = %15.15f\n", k*h, mpfr_get_d(val, MPFR_RNDN));
}
*/
return 0;
}
| {
"alphanum_fraction": 0.5947995666,
"avg_line_length": 33.1121076233,
"ext": "c",
"hexsha": "62c66672399d4dcdb06db202399d66e527b3a582",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2bcaab45a9096ae078711b4f4e1495c2bead16a0",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "tom-klotz/ellipsoid-solvation",
"max_forks_repo_path": "src/testEllipsoid.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2bcaab45a9096ae078711b4f4e1495c2bead16a0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "tom-klotz/ellipsoid-solvation",
"max_issues_repo_path": "src/testEllipsoid.c",
"max_line_length": 230,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2bcaab45a9096ae078711b4f4e1495c2bead16a0",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "tom-klotz/ellipsoid-solvation",
"max_stars_repo_path": "src/testEllipsoid.c",
"max_stars_repo_stars_event_max_datetime": "2016-11-05T20:15:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-11-05T20:15:01.000Z",
"num_tokens": 5702,
"size": 14768
} |
//
// herk.h
// Linear Algebra Template Library
//
// Created by Rodney James on 1/6/12.
// Copyright (c) 2012 University of Colorado Denver. All rights reserved.
//
#ifndef _herk_h
#define _herk_h
/// @file herk.h Performs complex matrix-matrix multiplication operations resulting in Hermitian matrices.
#include <cctype>
#include "latl.h"
namespace LATL
{
/// @brief Performs multiplcation of a complex matrix with its conjugate transpose.
///
/// For complex matrix A, complex Hermitian matrix C, and real scalars alpha and beta
///
/// C := alpha*A*A'+beta*C or C := alpha*A'*A+beta*C
/// is computed.
/// @return 0 if success.
/// @return -i if the ith argument is invalid.
/// @tparam real_t Floating point type.
/// @param uplo Specifies whether the upper or lower triangular part of the Hermitian matrix C
/// is to be referenced:
///
/// if uplo = 'U' or 'u' then C is upper triangular,
/// if uplo = 'L' or 'l' then C is lower triangular.
/// @param trans Specifies the operation to be perfomed as follows:
///
/// if trans = 'N' or 'n' then C := alpha*A*A'+beta*C
/// if trans = 'C' or 'c' then C := alpha*A'*A+beta*C
/// @param n Specifies the order of the complex Hermitian matrix C. n>=0
/// @param k Specifies the other dimension of the complex matrix A (see below). k>=0
/// @param alpha Real scalar.
/// @param A Pointer to complex matrix.
///
/// if trans = 'N' or 'n' then A is n-by-k
/// if trans = 'C' or 'c' then A is k-by-n
/// @param ldA Column length of the matrix A. If trans = 'N' or 'n' ldA>=n, otherwise ldA>=k.
/// @param beta Real scalar.
/// @param C Pointer to complex Hermitian n-by-n matrix C.
/// Only the upper or lower triangular part of C is referenced, depending on the value of uplo above.
/// @param ldC Column length of the matrix C. ldC>=n
/// @ingroup BLAS
template <typename real_t>
int HERK(char uplo, char trans, int_t n, int_t k, real_t alpha, complex<real_t> *A, int_t ldA, real_t beta, complex<real_t> *C, int_t ldC)
{
using std::toupper;
uplo=toupper(uplo);
trans=toupper(trans);
using std::real;
using std::conj;
const complex<real_t> zero(0.0,0.0);
const real_t rzero=0.0;
const real_t one=1.0;
int_t i,j,l;
complex<real_t> *a,*c,*at;
complex<real_t> t;
real_t s;
if((uplo!='U')&&(uplo!='L'))
return -1;
else if((trans!='N')&&(trans!='C'))
return -2;
else if(n<0)
return -3;
else if(k<0)
return -4;
else if(ldA<((trans=='N')?n:k))
return -7;
else if(ldC<n)
return -10;
else if((n==0)||(((alpha==rzero)||(k==0))&&(beta==one)))
return 0;
if(alpha==zero)
{
if(uplo=='U')
{
c=C;
for(j=0;j<n;j++)
{
for(i=0;i<j;i++)
c[i]*=beta;
c[j]=beta*real(c[j]);
c+=ldC;
}
}
else
{
c=C;
for(j=0;j<n;j++)
{
c[j]=beta*real(c[j]);
for(i=j+1;i<n;i++)
c[i]*=beta;
c+=ldC;
}
}
}
else if(trans=='N')
{
if(uplo=='U')
{
c=C;
for(j=0;j<n;j++)
{
for(i=0;i<j;i++)
c[i]*=beta;
c[j]=beta*real(c[j]);
a=A;
for(l=0;l<k;l++)
{
t=alpha*conj(a[j]);
for(i=0;i<j;i++)
c[i]+=t*a[i];
c[j]=real(c[j])+real(t*a[i]);
a+=ldA;
}
c+=ldC;
}
}
else
{
c=C;
for(j=0;j<n;j++)
{
c[j]=beta*real(c[j]);
for(i=j+1;i<n;i++)
c[i]*=beta;
a=A;
for(l=0;l<k;l++)
{
t=alpha*conj(a[j]);
c[j]=real(c[j])+real(t*a[j]);
for(i=j+1;i<n;i++)
c[i]+=t*a[i];
a+=ldA;
}
c+=ldC;
}
}
}
else
{
if(uplo=='U')
{
c=C;
at=A;
for(j=0;j<n;j++)
{
a=A;
for(i=0;i<j;i++)
{
t=zero;
for(l=0;l<k;l++)
t+=conj(a[l])*at[l];
c[i]=alpha*t+beta*c[i];
a+=ldA;
}
s=rzero;
for(l=0;l<k;l++)
s+=real(conj(at[l])*at[l]);
c[j]=alpha*s+beta*real(c[j]);
at+=ldA;
c+=ldC;
}
}
else
{
at=A;
c=C;
for(j=0;j<n;j++)
{
s=rzero;
for(l=0;l<k;l++)
s+=real(conj(at[l])*at[l]);
c[j]=alpha*s+beta*real(c[j]);
a=A+(j+1)*ldA;
for(i=j+1;i<n;i++)
{
t=zero;
for(l=0;l<k;l++)
t+=conj(a[l])*at[l];
c[i]=alpha*t+beta*c[i];
a+=ldA;
}
at+=ldA;
c+=ldC;
}
}
}
return 0;
}
#ifdef __latl_cblas
#include <cblas.h>
template <> int HERK<float>(char uplo, char trans, int_t n, int_t k, float alpha, complex<float> *A, int_t ldA, float beta, complex<float> *C, int_t ldC)
{
using std::toupper;
uplo=toupper(uplo);
trans=toupper(trans);
if((uplo!='U')&&(uplo!='L'))
return -1;
else if((trans!='N')&&(trans!='C'))
return -2;
else if(n<0)
return -3;
else if(k<0)
return -4;
else if(ldA<((trans=='N')?n:k))
return -7;
else if(ldC<n)
return -10;
const CBLAS_UPLO Uplo=(uplo=='U')?CblasUpper:CblasLower;
const CBLAS_TRANSPOSE Trans=(trans=='N')?CblasNoTrans:((trans=='T')?CblasTrans:CblasConjTrans);
cblas_cherk(CblasColMajor,Uplo,Trans,n,k,alpha,A,ldA,beta,C,ldC);
return 0;
}
template <> int HERK<double>(char uplo, char trans, int_t n, int_t k, double alpha, complex<double> *A, int_t ldA, double beta, complex<double> *C, int_t ldC)
{
using std::toupper;
uplo=toupper(uplo);
trans=toupper(trans);
if((uplo!='U')&&(uplo!='L'))
return -1;
else if((trans!='N')&&(trans!='C'))
return -2;
else if(n<0)
return -3;
else if(k<0)
return -4;
else if(ldA<((trans=='N')?n:k))
return -7;
else if(ldC<n)
return -10;
const CBLAS_UPLO Uplo=(uplo=='U')?CblasUpper:CblasLower;
const CBLAS_TRANSPOSE Trans=(trans=='N')?CblasNoTrans:((trans=='T')?CblasTrans:CblasConjTrans);
cblas_zherk(CblasColMajor,Uplo,Trans,n,k,alpha,A,ldA,beta,C,ldC);
return 0;
}
#endif
}
#endif
| {
"alphanum_fraction": 0.438431051,
"avg_line_length": 28.1423076923,
"ext": "h",
"hexsha": "bf257db6a3f412c266b6b4512c9077fb5655c476",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-09T23:18:24.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-02-01T06:46:36.000Z",
"max_forks_repo_head_hexsha": "df838fb44a1ef5c77b57bf60bd46eaeff8db3492",
"max_forks_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_forks_repo_name": "langou/latl",
"max_forks_repo_path": "include/herk.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df838fb44a1ef5c77b57bf60bd46eaeff8db3492",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_issues_repo_name": "langou/latl",
"max_issues_repo_path": "include/herk.h",
"max_line_length": 161,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "df838fb44a1ef5c77b57bf60bd46eaeff8db3492",
"max_stars_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_stars_repo_name": "langou/latl",
"max_stars_repo_path": "include/herk.h",
"max_stars_repo_stars_event_max_datetime": "2022-02-09T23:18:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-12-13T09:10:11.000Z",
"num_tokens": 2054,
"size": 7317
} |
#ifndef Photometry_h
#define Photometry_h
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/
/* SPDX-License-Identifier: CC0-1.0 */
#include <string>
#include <vector>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_min.h>
#include <gsl/gsl_roots.h>
namespace Isis {
class Pvl;
class PhotoModel;
class AtmosModel;
class NormModel;
/**
* @author ????-??-?? Unknown
*
* @internal
* @history 2007-08-02 Steven Lambright - Fixed memory leak
* @history 2008-03-07 Janet Barrett - Added SetPhotomWl method to allow
* the application to set the p_normWavelength variable for
* use by MoonAlbedo normalization.
* @history 2008-06-18 Steven Koechle - Fixed Documentation Errors
* @history 2008-07-09 Steven Lambright - Fixed unit test
* @history 2011-08-19 Sharmila Prasad - Implemented brentminimizer using GSL
* @history 2011-09-15 Sharmila Prasad - Implemented brent's root solver using GSL
*/
class Photometry {
public:
Photometry(Pvl &pvl);
Photometry() {};
virtual ~Photometry();
//! Calculate the surface brightness
void Compute(double pha, double inc, double ema, double dn,
double &albedo, double &mult, double &base);
void Compute(double pha, double inc, double ema, double deminc,
double demema, double dn, double &albedo,
double &mult, double &base);
//! Set the wavelength
virtual void SetPhotomWl(double wl);
//! Double precision version of bracketing algorithm ported from Python.
//! Solution bracketing for 1-D minimization routine.
static void minbracket(double &xa, double &xb, double &xc, double &fa,
double &fb, double &fc, double Func(double par, void *params),
void *params);
//! Brent's method 1-D minimization routine using GSL's r8Brent minimization Algorithm
static int brentminimizer(double x_lower, double x_upper, gsl_function *Func,
double & x_minimum, double tolerance);
//! GSL's the Brent-Dekker method (Brent's method) combines an interpolation strategy
//! with the bisection algorithm to estimate the root of the quadratic function.
static int brentsolver(double x_lo, double x_hi, gsl_function *Func, double tolerance, double &root);
PhotoModel *GetPhotoModel() const {
return p_phtPmodel;
}
AtmosModel *GetAtmosModel() const {
return p_phtAmodel;
}
NormModel *GetNormModel() const {
return p_phtNmodel;
}
protected:
AtmosModel *p_phtAmodel;
PhotoModel *p_phtPmodel;
NormModel *p_phtNmodel;
};
};
#endif
| {
"alphanum_fraction": 0.6656606304,
"avg_line_length": 35.0823529412,
"ext": "h",
"hexsha": "2b15c3f213a5380600e57d74aa71c3573312e978",
"lang": "C",
"max_forks_count": 164,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T10:22:29.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-30T21:15:44.000Z",
"max_forks_repo_head_hexsha": "2c40e08caed09968ea01d5a767a676172ad20080",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "jlaura/isis3",
"max_forks_repo_path": "isis/src/base/objs/Photometry/Photometry.h",
"max_issues_count": 3825,
"max_issues_repo_head_hexsha": "aab0e63088046690e6c031881825596c1c2cc380",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:45:20.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-12-11T21:27:34.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "kdl222/ISIS3",
"max_issues_repo_path": "isis/src/base/objs/Photometry/Photometry.h",
"max_line_length": 107,
"max_stars_count": 134,
"max_stars_repo_head_hexsha": "aab0e63088046690e6c031881825596c1c2cc380",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "kdl222/ISIS3",
"max_stars_repo_path": "isis/src/base/objs/Photometry/Photometry.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T03:53:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-01-18T00:16:24.000Z",
"num_tokens": 749,
"size": 2982
} |
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <math.h>
#include <string.h>
#include "cconfigspace_internal.h"
#include "distribution_internal.h"
struct _ccs_distribution_mixture_data_s {
_ccs_distribution_common_data_t common_data;
size_t num_distributions;
ccs_distribution_t *distributions;
ccs_interval_t *bounds;
ccs_float_t *weights;
};
typedef struct _ccs_distribution_mixture_data_s _ccs_distribution_mixture_data_t;
static ccs_result_t
_ccs_distribution_mixture_del(ccs_object_t o) {
struct _ccs_distribution_mixture_data_s *data =
(struct _ccs_distribution_mixture_data_s *)(((ccs_distribution_t)o)->data);
for (size_t i = 0; i < data->num_distributions; i++) {
ccs_release_object(data->distributions[i]);
}
return CCS_SUCCESS;
}
static ccs_result_t
_ccs_distribution_mixture_get_bounds(_ccs_distribution_data_t *data,
ccs_interval_t *interval_ret);
static ccs_result_t
_ccs_distribution_mixture_samples(_ccs_distribution_data_t *data,
ccs_rng_t rng,
size_t num_values,
ccs_numeric_t *values);
static ccs_result_t
_ccs_distribution_mixture_strided_samples(_ccs_distribution_data_t *data,
ccs_rng_t rng,
size_t num_values,
size_t stride,
ccs_numeric_t *values);
static ccs_result_t
_ccs_distribution_mixture_soa_samples(_ccs_distribution_data_t *data,
ccs_rng_t rng,
size_t num_values,
ccs_numeric_t **values);
static _ccs_distribution_ops_t _ccs_distribution_mixture_ops = {
{ &_ccs_distribution_mixture_del },
&_ccs_distribution_mixture_samples,
&_ccs_distribution_mixture_get_bounds,
&_ccs_distribution_mixture_strided_samples,
&_ccs_distribution_mixture_soa_samples
};
ccs_result_t
ccs_create_mixture_distribution(size_t num_distributions,
ccs_distribution_t *distributions,
ccs_float_t *weights,
ccs_distribution_t *distribution_ret) {
CCS_CHECK_ARY(num_distributions, distributions);
CCS_CHECK_ARY(num_distributions, weights);
CCS_CHECK_PTR(distribution_ret);
if (!num_distributions || num_distributions > INT64_MAX)
return -CCS_INVALID_VALUE;
ccs_float_t sum = 0.0;
size_t dimension, i, j;
ccs_result_t err;
CCS_VALIDATE(ccs_distribution_get_dimension(distributions[0], &dimension));
for(i = 1; i < num_distributions; i++) {
size_t dimension_tmp;
CCS_VALIDATE(ccs_distribution_get_dimension(distributions[i], &dimension_tmp));
if (dimension != dimension_tmp)
return -CCS_INVALID_DISTRIBUTION;
}
for(i = 0; i < num_distributions; i++) {
if (weights[i] < 0.0)
return -CCS_INVALID_VALUE;
sum += weights[i];
}
if (sum == 0.0)
return -CCS_INVALID_VALUE;
ccs_float_t inv_sum = 1.0/sum;
if (isnan(inv_sum) || !isfinite(inv_sum))
return -CCS_INVALID_VALUE;
uintptr_t mem;
uintptr_t cur_mem;
uintptr_t tmp_mem;
ccs_interval_t *bounds_tmp;
ccs_numeric_type_t *data_types_tmp;
ccs_distribution_t distrib;
_ccs_distribution_mixture_data_t *distrib_data;
mem = (uintptr_t)calloc(1,
sizeof(struct _ccs_distribution_s) +
sizeof(_ccs_distribution_mixture_data_t) +
sizeof(ccs_distribution_t)*num_distributions +
sizeof(ccs_interval_t)*dimension +
sizeof(ccs_float_t)*(num_distributions + 1) +
sizeof(ccs_numeric_type_t)*dimension);
if (!mem)
return -CCS_OUT_OF_MEMORY;
cur_mem = mem;
tmp_mem = (uintptr_t)calloc(1,
sizeof(ccs_interval_t)*num_distributions +
sizeof(ccs_numeric_type_t)*dimension);
if (!tmp_mem) {
err = -CCS_OUT_OF_MEMORY;
goto memory;
}
bounds_tmp = (ccs_interval_t *)tmp_mem;
data_types_tmp = (ccs_numeric_type_t *)(tmp_mem + sizeof(ccs_interval_t)*num_distributions);
distrib = (ccs_distribution_t)cur_mem;
cur_mem += sizeof(struct _ccs_distribution_s);
_ccs_object_init(&(distrib->obj), CCS_DISTRIBUTION, (_ccs_object_ops_t *)&_ccs_distribution_mixture_ops);
distrib_data = (_ccs_distribution_mixture_data_t *)(cur_mem);
cur_mem += sizeof(_ccs_distribution_mixture_data_t);
distrib_data->common_data.type = CCS_MIXTURE;
distrib_data->common_data.dimension = dimension;
distrib_data->num_distributions = num_distributions;
distrib_data->distributions = (ccs_distribution_t *)(cur_mem);
cur_mem += sizeof(ccs_distribution_t)*num_distributions;
distrib_data->bounds = (ccs_interval_t *)(cur_mem);
cur_mem += sizeof(ccs_interval_t)*dimension;
distrib_data->weights = (ccs_float_t *)(cur_mem);
cur_mem += sizeof(ccs_float_t)*(num_distributions + 1);
distrib_data->common_data.data_types = (ccs_numeric_type_t *)(cur_mem);
cur_mem += sizeof(ccs_numeric_type_t)*dimension;
CCS_VALIDATE_ERR_GOTO(err,
ccs_distribution_get_data_types(distributions[0], distrib_data->common_data.data_types),
tmpmemory);
for (i = 1; i < num_distributions; i++) {
CCS_VALIDATE_ERR_GOTO(err,
ccs_distribution_get_data_types(distributions[i], data_types_tmp),
tmpmemory);
for (j = 0; j < dimension; j++)
if(distrib_data->common_data.data_types[j] != data_types_tmp[j]) {
err = -CCS_INVALID_DISTRIBUTION;
goto tmpmemory;
}
}
CCS_VALIDATE_ERR_GOTO(err,
ccs_distribution_get_bounds(distributions[0], distrib_data->bounds),
tmpmemory);
for (i = 1; i < num_distributions; i++) {
CCS_VALIDATE_ERR_GOTO(err,
ccs_distribution_get_bounds(distributions[i], bounds_tmp),
tmpmemory);
for (j = 0; j < dimension; j++) {
CCS_VALIDATE_ERR_GOTO(err,
ccs_interval_union(distrib_data->bounds + j, bounds_tmp + j,
distrib_data->bounds + j), tmpmemory);
}
}
distrib_data->weights[0] = 0.0;
for (i = 1; i <= num_distributions; i++) {
distrib_data->weights[i] = distrib_data->weights[i-1] + weights[i-1] * inv_sum;
}
distrib_data->weights[num_distributions] = 1.0;
if (1.0 < distrib_data->weights[num_distributions-1]) {
free((void *)mem);
return -CCS_INVALID_VALUE;
}
for (i = 0; i < num_distributions; i++) {
CCS_VALIDATE_ERR_GOTO(err, ccs_retain_object(distributions[i]), distrib);
distrib_data->distributions[i] = distributions[i];
}
distrib->data = (_ccs_distribution_data_t *)distrib_data;
*distribution_ret = distrib;
free((void *)tmp_mem);
return CCS_SUCCESS;
distrib:
for (i = 0; i < num_distributions; i++) {
if (distrib_data->distributions[i])
ccs_release_object(distributions[i]);
}
tmpmemory:
free((void *)tmp_mem);
memory:
free((void *)mem);
return err;
}
static ccs_result_t
_ccs_distribution_mixture_get_bounds(_ccs_distribution_data_t *data,
ccs_interval_t *interval_ret) {
_ccs_distribution_mixture_data_t *d = (_ccs_distribution_mixture_data_t *)data;
memcpy(interval_ret, d->bounds, d->common_data.dimension*sizeof(ccs_interval_t));
return CCS_SUCCESS;
}
static inline _ccs_distribution_ops_t *
ccs_distribution_get_ops(ccs_distribution_t distribution) {
return (_ccs_distribution_ops_t *)distribution->obj.ops;
}
static ccs_result_t
_ccs_distribution_mixture_samples(_ccs_distribution_data_t *data,
ccs_rng_t rng,
size_t num_values,
ccs_numeric_t *values) {
_ccs_distribution_mixture_data_t *d = (_ccs_distribution_mixture_data_t *)data;
size_t dim = d->common_data.dimension;
gsl_rng *grng;
CCS_VALIDATE(ccs_rng_get_gsl_rng(rng, &grng));
for (size_t i = 0; i < num_values; i++) {
ccs_float_t rnd = gsl_rng_uniform(grng);
ccs_int_t index = ccs_dichotomic_search(d->num_distributions, d->weights, rnd);
CCS_VALIDATE(ccs_distribution_get_ops(d->distributions[index])->samples(d->distributions[index]->data, rng, 1, values + i*dim));
}
return CCS_SUCCESS;
}
static ccs_result_t
_ccs_distribution_mixture_strided_samples(_ccs_distribution_data_t *data,
ccs_rng_t rng,
size_t num_values,
size_t stride,
ccs_numeric_t *values) {
_ccs_distribution_mixture_data_t *d = (_ccs_distribution_mixture_data_t *)data;
gsl_rng *grng;
CCS_VALIDATE(ccs_rng_get_gsl_rng(rng, &grng));
for (size_t i = 0; i < num_values; i++) {
ccs_float_t rnd = gsl_rng_uniform(grng);
ccs_int_t index = ccs_dichotomic_search(d->num_distributions, d->weights, rnd);
CCS_VALIDATE(ccs_distribution_get_ops(d->distributions[index])->samples(d->distributions[index]->data, rng, 1, values + i*stride));
}
return CCS_SUCCESS;
}
static ccs_result_t
_ccs_distribution_mixture_soa_samples(_ccs_distribution_data_t *data,
ccs_rng_t rng,
size_t num_values,
ccs_numeric_t **values) {
_ccs_distribution_mixture_data_t *d = (_ccs_distribution_mixture_data_t *)data;
size_t dim = d->common_data.dimension;
int needed = 0;
ccs_numeric_t **p_values = (ccs_numeric_t**)alloca(dim*sizeof(ccs_numeric_t*));
for (size_t i = 0; i < dim; i++)
if (values[i]) {
needed = 1;
break;
}
if (!needed)
return CCS_SUCCESS;
gsl_rng *grng;
CCS_VALIDATE(ccs_rng_get_gsl_rng(rng, &grng));
for (size_t i = 0; i < num_values; i++) {
ccs_float_t rnd = gsl_rng_uniform(grng);
ccs_int_t index = ccs_dichotomic_search(d->num_distributions, d->weights, rnd);
for (size_t j = 0; j < dim; j++)
if (values[j])
p_values[j] = values[j] + i;
CCS_VALIDATE(ccs_distribution_get_ops(d->distributions[index])->soa_samples(d->distributions[index]->data, rng, 1, p_values));
}
return CCS_SUCCESS;
}
ccs_result_t
ccs_mixture_distribution_get_num_distributions(ccs_distribution_t distribution,
size_t *num_distributions_ret) {
CCS_CHECK_DISTRIBUTION(distribution, CCS_MIXTURE);
CCS_CHECK_PTR(num_distributions_ret);
_ccs_distribution_mixture_data_t * data = (_ccs_distribution_mixture_data_t *)distribution->data;
*num_distributions_ret = data->num_distributions;
return CCS_SUCCESS;
}
ccs_result_t
ccs_mixture_distribution_get_distributions(ccs_distribution_t distribution,
size_t num_distributions,
ccs_distribution_t *distributions,
size_t *num_distributions_ret) {
CCS_CHECK_DISTRIBUTION(distribution, CCS_MIXTURE);
CCS_CHECK_ARY(num_distributions, distributions);
if (!distributions && !num_distributions_ret)
return -CCS_INVALID_VALUE;
_ccs_distribution_mixture_data_t * data = (_ccs_distribution_mixture_data_t *)distribution->data;
if (distributions) {
if (num_distributions < data->num_distributions)
return -CCS_INVALID_VALUE;
for (size_t i = 0; i < data->num_distributions; i++)
distributions[i] = data->distributions[i];
for (size_t i = data->num_distributions; i < num_distributions; i++)
distributions[i] = NULL;
}
if (num_distributions_ret)
*num_distributions_ret = data->num_distributions;
return CCS_SUCCESS;
}
ccs_result_t
ccs_mixture_distribution_get_weights(ccs_distribution_t distribution,
size_t num_weights,
ccs_float_t *weights,
size_t *num_weights_ret) {
CCS_CHECK_DISTRIBUTION(distribution, CCS_MIXTURE);
CCS_CHECK_ARY(num_weights, weights);
if (!weights && !num_weights_ret)
return -CCS_INVALID_VALUE;
_ccs_distribution_mixture_data_t * data = (_ccs_distribution_mixture_data_t *)distribution->data;
if (weights) {
if (num_weights < data->num_distributions)
return -CCS_INVALID_VALUE;
for (size_t i = 0; i < data->num_distributions; i++)
weights[i] = data->weights[i+1] - data->weights[i];
for (size_t i = data->num_distributions; i < num_weights; i++)
weights[i] = 0.0;
}
if (num_weights_ret)
*num_weights_ret = data->num_distributions;
return CCS_SUCCESS;
}
| {
"alphanum_fraction": 0.6631078554,
"avg_line_length": 38.3044776119,
"ext": "c",
"hexsha": "b32bf6d3c7dc5aedb2cfd99588cb12343eaf9c36",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-12-07T17:54:11.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-09-16T18:20:47.000Z",
"max_forks_repo_head_hexsha": "dd8c976eca2a510c995862cc5c871e81932f3ff4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "deephyper/CCS",
"max_forks_repo_path": "src/distribution_mixture.c",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "dd8c976eca2a510c995862cc5c871e81932f3ff4",
"max_issues_repo_issues_event_max_datetime": "2021-12-15T10:48:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-12-15T10:37:41.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "deephyper/CCS",
"max_issues_repo_path": "src/distribution_mixture.c",
"max_line_length": 133,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "dd8c976eca2a510c995862cc5c871e81932f3ff4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "deephyper/CCS",
"max_stars_repo_path": "src/distribution_mixture.c",
"max_stars_repo_stars_event_max_datetime": "2021-11-29T16:31:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-29T16:31:28.000Z",
"num_tokens": 3118,
"size": 12832
} |
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file oaisim.c
* \brief oaisim top level
* \author Navid Nikaein
* \date 2013-2015
* \version 1.0
* \company Eurecom
* \email: openair_tech@eurecom.fr
* \note
* \warning
*/
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cblas.h>
#include <execinfo.h>
#include "event_handler.h"
#include "SIMULATION/RF/defs.h"
#include "PHY/types.h"
#include "PHY/defs.h"
#include "PHY/LTE_TRANSPORT/proto.h"
#include "PHY/vars.h"
#include "SIMULATION/ETH_TRANSPORT/proto.h"
//#ifdef OPENAIR2
#include "LAYER2/MAC/defs.h"
#include "LAYER2/MAC/proto.h"
#include "LAYER2/MAC/vars.h"
#include "pdcp.h"
#include "RRC/LITE/vars.h"
#include "RRC/NAS/nas_config.h"
#include "SCHED/defs.h"
#include "SCHED/vars.h"
#include "system.h"
#include "PHY/TOOLS/lte_phy_scope.h"
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
#include "PHY/TOOLS/smbv.h"
char smbv_fname[] = "smbv_config_file.smbv";
unsigned short smbv_nframes = 4; // how many frames to configure 1,..,4
unsigned short config_frames[4] = {2,9,11,13};
unsigned char smbv_frame_cnt = 0;
uint8_t config_smbv = 0;
char smbv_ip[16];
#endif
#include "flexran_agent.h"
#include "oaisim_functions.h"
#include "oaisim.h"
#include "oaisim_config.h"
#include "UTIL/OCG/OCG_extern.h"
#include "cor_SF_sim.h"
#include "UTIL/OMG/omg_constants.h"
#include "UTIL/FIFO/pad_list.h"
#include "enb_app.h"
#include "../PROC/interface.h"
#include "../PROC/channel_sim_proc.h"
#include "../PROC/Tsync.h"
#include "../PROC/Process.h"
#include "UTIL/LOG/vcd_signal_dumper.h"
#include "UTIL/OTG/otg_kpi.h"
#include "assertions.h"
#if defined(ENABLE_ITTI)
# include "intertask_interface.h"
# include "create_tasks.h"
#endif
#include "T.h"
/*
DCI0_5MHz_TDD0_t UL_alloc_pdu;
DCI1A_5MHz_TDD_1_6_t CCCH_alloc_pdu;
DCI2_5MHz_2A_L10PRB_TDD_t DLSCH_alloc_pdu1;
DCI2_5MHz_2A_M10PRB_TDD_t DLSCH_alloc_pdu2;
*/
#define UL_RB_ALLOC computeRIV(lte_frame_parms->N_RB_UL,0,24)
#define CCCH_RB_ALLOC computeRIV(lte_frame_parms->N_RB_UL,0,3)
#define RA_RB_ALLOC computeRIV(lte_frame_parms->N_RB_UL,0,3)
#define DLSCH_RB_ALLOC 0x1fff
#define DECOR_DIST 100
#define SF_VAR 10
//constant for OAISIM soft realtime calibration
//#define SF_DEVIATION_OFFSET_NS 100000 /*= 0.1ms : should be as a number of UE */
//#define SLEEP_STEP_US 100 /* = 0.01ms could be adaptive, should be as a number of UE */
//#define K 2 /* averaging coefficient */
//#define TARGET_SF_TIME_NS 1000000 /* 1ms = 1000000 ns */
uint8_t usim_test = 0;
frame_t frame = 0;
char stats_buffer[16384];
channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM_CCs];
channel_desc_t *UE2RU[NUMBER_OF_UE_MAX][NUMBER_OF_RU_MAX][MAX_NUM_CCs];
//Added for PHY abstraction
node_desc_t *enb_data[NUMBER_OF_RU_MAX];
node_desc_t *ue_data[NUMBER_OF_UE_MAX];
pthread_cond_t sync_cond;
pthread_mutex_t sync_mutex;
int sync_var=-1;
pthread_mutex_t subframe_mutex;
int subframe_ru_mask=0,subframe_UE_mask=0;
openair0_config_t openair0_cfg[MAX_CARDS];
uint32_t downlink_frequency[MAX_NUM_CCs][4];
int32_t uplink_frequency_offset[MAX_NUM_CCs][4];
openair0_rf_map rf_map[MAX_NUM_CCs];
#if defined(ENABLE_ITTI)
volatile int start_eNB = 0;
volatile int start_UE = 0;
#endif
volatile int oai_exit = 0;
//int32_t **rxdata;
//int32_t **txdata;
uint16_t sf_ahead=4;
uint8_t nfapi_mode = 0;
// Added for PHY abstraction
extern node_list* ue_node_list;
extern node_list* enb_node_list;
extern int pdcp_period, omg_period;
extern double **s_re, **s_im, **r_re, **r_im, **r_re0, **r_im0;
int map1, map2;
extern double **ShaF;
double snr_dB, sinr_dB, snr_direction; //,sinr_direction;
extern double snr_step;
extern uint8_t set_sinr;
extern uint8_t ue_connection_test;
extern uint8_t set_seed;
extern uint8_t target_dl_mcs;
extern uint8_t target_ul_mcs;
extern uint8_t abstraction_flag;
extern uint8_t ethernet_flag;
extern uint16_t Nid_cell;
double cpuf;
#include "threads_t.h"
threads_t threads= {-1,-1,-1,-1,-1,-1,-1};
//#ifdef XFORMS
int otg_enabled;
int xforms=0;
//#endif
time_stats_t oaisim_stats;
time_stats_t oaisim_stats_f;
time_stats_t dl_chan_stats;
time_stats_t ul_chan_stats;
// this should reflect the channel models in openair1/SIMULATION/TOOLS/defs.h
mapping small_scale_names[] = {
{ "custom", custom }, { "SCM_A", SCM_A },
{ "SCM_B", SCM_B }, { "SCM_C", SCM_C },
{ "SCM_D", SCM_D }, { "EPA", EPA },
{ "EVA", EVA }, { "ETU", ETU },
{ "MBSFN", MBSFN }, { "Rayleigh8", Rayleigh8 },
{ "Rayleigh1", Rayleigh1 }, { "Rayleigh1_800", Rayleigh1_800 },
{ "Rayleigh1_corr", Rayleigh1_corr }, { "Rayleigh1_anticorr", Rayleigh1_anticorr },
{ "Rice8", Rice8 }, { "Rice1", Rice1 }, { "Rice1_corr", Rice1_corr },
{ "Rice1_anticorr", Rice1_anticorr }, { "AWGN", AWGN }, { NULL,-1 }
};
#if !defined(ENABLE_ITTI)
static void *
sigh (void *arg);
#endif
void
oai_shutdown (void);
void reset_opp_meas_oaisim (void);
void wait_eNBs(void)
{
return;
}
void
help (void)
{
printf ("Usage: oaisim -h -a -F -C tdd_config -K [log_file] -V [vcd_file] -R N_RB_DL -e -x transmission_mode -m target_dl_mcs -r(ate_adaptation) -n n_frames -s snr_dB -k ricean_factor -t max_delay -f forgetting factor -A channel_model -z cooperation_flag -u nb_local_ue -U UE mobility -b nb_local_enb -B eNB_mobility -M ethernet_flag -p nb_master -g multicast_group -l log_level -c ocg_enable -T traffic model -D multicast network device\n");
printf ("-h provides this help message!\n");
printf ("-a Activates PHY abstraction mode\n");
printf ("-A set the multipath channel simulation, options are: SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr,Rayleigh1_anticorr, Rice8,, Rice1, AWGN \n");
printf ("-b Set the number of local eNB\n");
printf ("-B Set the mobility model for eNB, options are: STATIC, RWP, RWALK, \n");
printf ("-c [1,2,3,4] Activate the config generator (OCG) to process the scenario descriptor, or give the scenario manually: -c template_1.xml \n");
printf ("-C [0-6] Sets TDD configuration\n");
printf ("-e Activates extended prefix mode\n");
printf ("-E Random number generator seed\n");
printf ("-f Set the forgetting factor for time-variation\n");
printf ("-F Activates FDD transmission (TDD is default)\n");
printf ("-g Set multicast group ID (0,1,2,3) - valid if M is set\n");
printf ("-G Enable background traffic \n");
printf ("-H Enable handover operation (default disabled) \n");
printf ("-I Enable CLI interface (to connect use telnet localhost 1352)\n");
printf ("-k Set the Ricean factor (linear)\n");
printf ("-K [log_file] Enable ITTI logging into log_file\n");
printf ("-l Set the global log level (8:trace, 7:debug, 6:info, 4:warn, 3:error) \n");
printf ("-L [0-1] 0 to disable new link adaptation, 1 to enable new link adapatation\n");
printf ("-m Gives a fixed DL mcs for eNB scheduler\n");
printf ("-M Set the machine ID for Ethernet-based emulation\n");
printf ("-n Set the number of frames for the simulation. 0 for no limit\n");
printf ("-O [enb_conf_file] eNB configuration file name\n");
printf ("-p Set the total number of machine in emulation - valid if M is set\n");
printf ("-P [trace type] Enable protocol analyzer. Possible values for OPT:\n");
printf (" - wireshark: Enable tracing of layers above PHY using an UDP socket\n");
printf (" - pcap: Enable tracing of layers above PHY to a pcap file\n");
printf (" - tshark: Not implemented yet\n");
printf ("-q Enable Openair performance profiler \n");
printf ("-Q Activate and set the MBMS service: 0 : not used (default eMBMS disabled), 1: eMBMS and RRC Connection enabled, 2: eMBMS relaying and RRC Connection enabled, 3: eMBMS enabled, RRC Connection disabled, 4: eMBMS relaying enabled, RRC Connection disabled\n");
printf ("-R [6,15,25,50,75,100] Sets N_RB_DL\n");
printf ("-r Activates rate adaptation (DL for now)\n");
printf ("-s snr_dB set a fixed (average) SNR, this deactivates the openair channel model generator (OCM)\n");
printf ("-S snir_dB set a fixed (average) SNIR, this deactivates the openair channel model generator (OCM)\n");
printf ("-t Gives a fixed UL mcs for eNB scheduler\n");
printf ("-T activate the traffic generator. Valide options are m2m,scbr,mcbr,bcbr,auto_pilot,bicycle_race,open_arena,team_fortress,m2m_traffic,auto_pilot_l,auto_pilot_m,auto_pilot_h,auto_pilot_e,virtual_game_l,virtual_game_m,virtual_game_h,virtual_game_f,alarm_humidity,alarm_smoke,alarm_temperature,openarena_dl,openarena_ul,voip_g711,voip_g729,video_vbr_10mbps,video_vbr_4mbps,video_vbr_2mbp,video_vbr_768kbps,video_vbr_384kbps,video_vbr_192kpbs,background_users\n");
printf ("-u Set the number of local UE\n");
printf ("-U Set the mobility model for UE, options are: STATIC, RWP, RWALK\n");
printf ("-V [vcd_file] Enable VCD dump into vcd_file\n");
printf ("-w number of CBA groups, if not specified or zero, CBA is inactive\n");
#ifdef SMBV
printf ("-W IP address to connect to Rohde&Schwarz SMBV100A and configure SMBV from config file. -W0 uses default IP 192.168.12.201\n");
#else
printf ("-W [Rohde&Schwarz SMBV100A functions disabled. Recompile with SMBV=1]\n");
#endif
printf ("-x deprecated. Set the transmission mode in config file!\n");
printf ("-y Set the number of receive antennas at the UE (1 or 2)\n");
printf ("-Y Set the global log verbosity (none, low, medium, high, full) \n");
printf ("-z Set the cooperation flag (0 for no cooperation, 1 for delay diversity and 2 for distributed alamouti\n");
printf ("-Z Reserved\n");
printf ("--xforms Activate the grapical scope\n");
#if T_TRACER
printf ("--T_port [port] use given port\n");
printf ("--T_nowait don't wait for tracer, start immediately\n");
printf ("--T_dont_fork to ease debugging with gdb\n");
#endif
}
pthread_t log_thread;
void
log_thread_init (void)
{
//create log_list
//log_list_init(&log_list);
#ifndef LOG_NO_THREAD
log_shutdown = 0;
if ((pthread_mutex_init (&log_lock, NULL) != 0)
|| (pthread_cond_init (&log_notify, NULL) != 0)) {
return;
}
if (pthread_create (&log_thread, NULL, log_thread_function, (void*) NULL)
!= 0) {
log_thread_finalize ();
return;
}
#endif
}
//Call it after the last LOG call
int
log_thread_finalize (void)
{
int err = 0;
#ifndef LOG_NO_THREAD
if (pthread_mutex_lock (&log_lock) != 0) {
return -1;
}
log_shutdown = 1;
/* Wake up LOG thread */
if ((pthread_cond_broadcast (&log_notify) != 0)
|| (pthread_mutex_unlock (&log_lock) != 0)) {
err = -1;
}
if (pthread_join (log_thread, NULL) != 0) {
err = -1;
}
if (pthread_mutex_unlock (&log_lock) != 0) {
err = -1;
}
if (!err) {
//log_list_free(&log_list);
pthread_mutex_lock (&log_lock);
pthread_mutex_destroy (&log_lock);
pthread_cond_destroy (&log_notify);
}
#endif
return err;
}
#if defined(ENABLE_ITTI)
static void set_cli_start(module_id_t module_idP, uint8_t start)
{
if (module_idP < NB_eNB_INST) {
oai_emulation.info.cli_start_enb[module_idP] = start;
} else {
oai_emulation.info.cli_start_ue[module_idP - NB_eNB_INST] = start;
}
}
#endif
#ifdef OPENAIR2
int omv_write(int pfd, node_list* enb_node_list, node_list* ue_node_list, Data_Flow_Unit omv_data)
{
module_id_t i;
omv_data.end = 0;
//omv_data.total_num_nodes = NB_UE_INST + NB_eNB_INST;
for (i = 0; i < NB_eNB_INST; i++) {
if (enb_node_list != NULL) {
omv_data.geo[i].x = (enb_node_list->node->x_pos < 0.0) ? 0.0 : enb_node_list->node->x_pos;
omv_data.geo[i].y = (enb_node_list->node->y_pos < 0.0) ? 0.0 : enb_node_list->node->y_pos;
omv_data.geo[i].z = 1.0;
omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_enb;
omv_data.geo[i].node_type = 0; //eNB
enb_node_list = enb_node_list->next;
omv_data.geo[i].Neighbors = 0;
/*
for (j = NB_RU; j < NB_UE_INST + NB_RU; j++) {
if (is_UE_active (i, j - NB_RU) == 1) {
omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
omv_data.geo[i].Neighbors++;
LOG_D(
OMG,
"[RU %d][UE %d] is_UE_active(i,j) %d geo (x%d, y%d) num neighbors %d\n", i, j-NB_RU, is_UE_active(i,j-NB_RU), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
}
}
*/
}
}
for (i = NB_RU; i < NB_UE_INST + NB_RU; i++) {
if (ue_node_list != NULL) {
omv_data.geo[i].x = (ue_node_list->node->x_pos < 0.0) ? 0.0 : ue_node_list->node->x_pos;
omv_data.geo[i].y = (ue_node_list->node->y_pos < 0.0) ? 0.0 : ue_node_list->node->y_pos;
omv_data.geo[i].z = 1.0;
omv_data.geo[i].mobility_type = oai_emulation.info.omg_model_ue;
omv_data.geo[i].node_type = 1; //UE
//trial
omv_data.geo[i].state = 1;
omv_data.geo[i].rnti = 88;
omv_data.geo[i].connected_eNB = 0;
omv_data.geo[i].RSRP = 66;
omv_data.geo[i].RSRQ = 55;
omv_data.geo[i].Pathloss = 44;
omv_data.geo[i].RSSI[0] = 33;
omv_data.geo[i].RSSI[1] = 22;
if ((sizeof(omv_data.geo[0].RSSI) / sizeof(omv_data.geo[0].RSSI[0])) > 2) {
omv_data.geo[i].RSSI[2] = 11;
}
ue_node_list = ue_node_list->next;
omv_data.geo[i].Neighbors = 0;
/*
for (j = 0; j < NB_RU; j++) {
if (is_UE_active (j, i - NB_RU) == 1) {
omv_data.geo[i].Neighbor[omv_data.geo[i].Neighbors] = j;
omv_data.geo[i].Neighbors++;
LOG_D(
OMG,
"[UE %d][RU %d] is_UE_active %d geo (x%d, y%d) num neighbors %d\n", i-NB_RU, j, is_UE_active(j,i-NB_RU), omv_data.geo[i].x, omv_data.geo[i].y, omv_data.geo[i].Neighbors);
}
}
*/
}
}
LOG_E(OMG, "pfd %d \n", pfd);
if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
perror ("write omv failed");
return 1;
}
void omv_end(int pfd, Data_Flow_Unit omv_data)
{
omv_data.end = 1;
if (write (pfd, &omv_data, sizeof(struct Data_Flow_Unit)) == -1)
perror ("write omv failed");
}
#endif
#ifdef OPENAIR2
int pfd[2]; // fd for omv : fixme: this could be a local var
#endif
#ifdef OPENAIR2
static Data_Flow_Unit omv_data;
#endif //ALU
static module_id_t UE_inst = 0;
static module_id_t eNB_inst = 0;
static module_id_t ru_id;
Packet_OTG_List_t *otg_pdcp_buffer;
typedef enum l2l1_task_state_e {
L2L1_WAITTING, L2L1_RUNNING, L2L1_TERMINATED,
} l2l1_task_state_t;
l2l1_task_state_t l2l1_state = L2L1_WAITTING;
extern openair0_timestamp current_ru_rx_timestamp[NUMBER_OF_RU_MAX][MAX_NUM_CCs];
extern openair0_timestamp current_UE_rx_timestamp[NUMBER_OF_UE_MAX][MAX_NUM_CCs];
extern openair0_timestamp last_eNB_rx_timestamp[NUMBER_OF_eNB_MAX][MAX_NUM_CCs];
extern openair0_timestamp last_UE_rx_timestamp[NUMBER_OF_UE_MAX][MAX_NUM_CCs];
/*------------------------------------------------------------------------------*/
void *
l2l1_task (void *args_p)
{
int CC_id;
// Framing variables
int32_t sf;
//char fname[64], vname[64];
//#ifdef XFORMS
// current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
// at eNB 0, an UL scope for every UE
FD_lte_phy_scope_ue *form_ue[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
FD_lte_phy_scope_enb *form_enb[NUMBER_OF_UE_MAX];
char title[255];
char xname[32] = "oaisim";
int xargc = 1;
char *xargv[1];
//#endif
#undef PRINT_STATS /* this undef is to avoid gcc warnings */
#define PRINT_STATS
#ifdef PRINT_STATS
//int len;
FILE *UE_stats[NUMBER_OF_UE_MAX];
FILE *UE_stats_th[NUMBER_OF_UE_MAX];
FILE *eNB_stats[NUMBER_OF_eNB_MAX];
FILE *eNB_avg_thr;
FILE *eNB_l2_stats;
char UE_stats_filename[255];
char eNB_stats_filename[255];
char UE_stats_th_filename[255];
char eNB_stats_th_filename[255];
#endif
if (xforms==1) {
xargv[0] = xname;
fl_initialize (&xargc, xargv, NULL, 0, 0);
eNB_inst = 0;
for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
// DL scope at UEs
form_ue[CC_id][UE_inst] = create_lte_phy_scope_ue();
sprintf (title, "LTE DL SCOPE eNB %d to UE %d CC_id %d", eNB_inst, UE_inst, CC_id);
fl_show_form (form_ue[CC_id][UE_inst]->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title);
if (PHY_vars_UE_g[UE_inst][CC_id]->use_ia_receiver == 1) {
fl_set_button(form_ue[CC_id][UE_inst]->button_0,1);
fl_set_object_label(form_ue[CC_id][UE_inst]->button_0, "IA Receiver ON");
fl_set_object_color(form_ue[CC_id][UE_inst]->button_0, FL_GREEN, FL_GREEN);
}
}
}
}
#ifdef PRINT_STATS
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
sprintf(UE_stats_filename,"UE_stats%d.txt",UE_inst);
UE_stats[UE_inst] = fopen (UE_stats_filename, "w");
}
for (eNB_inst=0; eNB_inst<NB_eNB_INST; eNB_inst++) {
sprintf(eNB_stats_filename,"eNB_stats%d.txt",eNB_inst);
eNB_stats[eNB_inst] = fopen (eNB_stats_filename, "w");
}
if(abstraction_flag==0) {
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(UE_stats_th_filename,"UE_stats_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode[0]);
UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
}
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(eNB_stats_th_filename,"eNB_stats_th_tx%d.txt",oai_emulation.info.transmission_mode[0]);
eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
} else {
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(UE_stats_th_filename,"UE_stats_abs_th%d_tx%d.txt",UE_inst,oai_emulation.info.transmission_mode[0]);
UE_stats_th[UE_inst] = fopen (UE_stats_th_filename, "w");
}
/* TODO: transmission_mode is defined per CC, we set 0 for now */
sprintf(eNB_stats_th_filename,"eNB_stats_abs_th_tx%d.txt",oai_emulation.info.transmission_mode[0]);
eNB_avg_thr = fopen (eNB_stats_th_filename, "w");
}
#ifdef OPENAIR2
eNB_l2_stats = fopen ("eNB_l2_stats.txt", "w");
LOG_I(EMU,"eNB_l2_stats=%p\n", eNB_l2_stats);
#endif
#endif
#if defined(ENABLE_ITTI)
MessageDef *message_p = NULL;
const char *msg_name = NULL;
int result;
itti_mark_task_ready (TASK_L2L1);
LOG_I(EMU, "TASK_L2L1 is READY\n");
if ((oai_emulation.info.nb_enb_local > 0) &&
(oai_emulation.info.node_function[0] < NGFI_RAU_IF4p5)) {
/* Wait for the initialize message */
do {
if (message_p != NULL) {
result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
}
itti_receive_msg (TASK_L2L1, &message_p);
msg_name = ITTI_MSG_NAME (message_p);
LOG_I(EMU, "TASK_L2L1 received %s in state L2L1_WAITTING\n", msg_name);
switch (ITTI_MSG_ID(message_p)) {
case INITIALIZE_MESSAGE:
l2l1_state = L2L1_RUNNING;
start_eNB = 1;
break;
case ACTIVATE_MESSAGE:
set_cli_start(ITTI_MSG_INSTANCE (message_p), 1);
break;
case DEACTIVATE_MESSAGE:
set_cli_start(ITTI_MSG_INSTANCE (message_p), 0);
break;
case TERMINATE_MESSAGE:
l2l1_state = L2L1_TERMINATED;
break;
default:
LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
break;
}
} while (l2l1_state == L2L1_WAITTING);
result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
}
#endif
module_id_t UE_id;
if (abstraction_flag == 1) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++)
dl_phy_sync_success (UE_id, 0, 0,1); //UE_id%NB_eNB_INST);
}
start_meas (&oaisim_stats);
for (frame = 0;
(l2l1_state != L2L1_TERMINATED) &&
((oai_emulation.info.n_frames_flag == 0) ||
(frame < oai_emulation.info.n_frames));
frame++) {
#if defined(ENABLE_ITTI)
do {
// Checks if a message has been sent to L2L1 task
itti_poll_msg (TASK_L2L1, &message_p);
if (message_p != NULL) {
msg_name = ITTI_MSG_NAME (message_p);
LOG_I(EMU, "TASK_L2L1 received %s\n", msg_name);
switch (ITTI_MSG_ID(message_p)) {
case ACTIVATE_MESSAGE:
set_cli_start(ITTI_MSG_INSTANCE (message_p), 1);
break;
case DEACTIVATE_MESSAGE:
set_cli_start(ITTI_MSG_INSTANCE (message_p), 0);
break;
case TERMINATE_MESSAGE:
l2l1_state = L2L1_TERMINATED;
break;
case MESSAGE_TEST:
break;
default:
LOG_E(EMU, "Received unexpected message %s\n", ITTI_MSG_NAME(message_p));
break;
}
result = itti_free (ITTI_MSG_ORIGIN_ID(message_p), message_p);
AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result);
}
} while(message_p != NULL);
#endif
//Run the aperiodic user-defined events
if (oai_emulation.info.oeh_enabled == 1)
execute_events (frame);
if (ue_connection_test == 1) {
if ((frame % 20) == 0) {
snr_dB += snr_direction;
sinr_dB -= snr_direction;
}
if (snr_dB == -20) {
snr_direction = snr_step;
} else if (snr_dB == 20) {
snr_direction = -snr_step;
}
}
oai_emulation.info.frame = frame;
//oai_emulation.info.time_ms += 1;
oai_emulation.info.time_s += 0.01; // emu time in s, each frame lasts for 10 ms // JNote: TODO check the coherency of the time and frame (I corrected it to 10 (instead of 0.01)
update_omg (frame); // frequency is defined in the omg_global params configurable by the user
update_omg_ocm ();
#ifdef OPENAIR2
// check if pipe is still open
if ((oai_emulation.info.omv_enabled == 1)) {
omv_write (pfd[1], enb_node_list, ue_node_list, omv_data);
}
#endif
for (sf = 0; sf < 10; sf++) {
LOG_D(EMU,"************************* Subframe %d\n",sf);
start_meas (&oaisim_stats_f);
wait_for_slot_isr ();
#if defined(ENABLE_ITTI)
itti_update_lte_time(frame % MAX_FRAME_NUMBER, sf<<1);
#endif
oai_emulation.info.time_ms = frame * 10 + sf;
#ifdef PROC
if(Channel_Flag==1)
Channel_Func(s_re2,s_im2,r_re2,r_im2,r_re02,r_im02,r_re0_d,r_im0_d,r_re0_u,r_im0_u,RU2UE,UE2RU,enb_data,ue_data,abstraction_flag,frame_parms,sf<<1);
if(Channel_Flag==0)
#endif
{ // SUBFRAME INNER PART
#if defined(ENABLE_ITTI)
log_set_instance_type (LOG_INSTANCE_ENB);
#endif
CC_id=0;
int all_done=0;
while (all_done==0) {
pthread_mutex_lock(&subframe_mutex);
int subframe_ru_mask_local = subframe_ru_mask;
int subframe_UE_mask_local = subframe_UE_mask;
pthread_mutex_unlock(&subframe_mutex);
LOG_D(EMU,"Frame %d, Subframe %d, NB_RU %d, NB_UE %d: Checking masks %x,%x\n",frame,sf,NB_RU,NB_UE_INST,subframe_ru_mask_local,subframe_UE_mask_local);
if ((subframe_ru_mask_local == ((1<<NB_RU)-1)) &&
(subframe_UE_mask_local == ((1<<NB_UE_INST)-1)))
all_done=1;
else
usleep(1500);
}
//clear subframe masks for next round
pthread_mutex_lock(&subframe_mutex);
subframe_ru_mask=0;
subframe_UE_mask=0;
pthread_mutex_unlock(&subframe_mutex);
// increment timestamps
/*
for (ru_id = oai_emulation.info.first_enb_local;
(ru_id
< (oai_emulation.info.first_enb_local
+ oai_emulation.info.nb_enb_local));
ru_id++) {
*/
for (ru_id=0;ru_id<NB_RU;ru_id++) {
current_ru_rx_timestamp[ru_id][CC_id] += RC.ru[ru_id]->frame_parms.samples_per_tti;
LOG_D(EMU,"RU %d/%d: TS %"PRIi64"\n",ru_id,CC_id,current_ru_rx_timestamp[ru_id][CC_id]);
}
for (UE_inst = 0; UE_inst<NB_UE_INST;UE_inst++) {
current_UE_rx_timestamp[UE_inst][CC_id] += PHY_vars_UE_g[UE_inst][CC_id]->frame_parms.samples_per_tti;
LOG_D(EMU,"UE %d/%d: TS %"PRIi64"\n",UE_inst,CC_id,current_UE_rx_timestamp[UE_inst][CC_id]);
}
for (eNB_inst = oai_emulation.info.first_enb_local;
(eNB_inst
< (oai_emulation.info.first_enb_local
+ oai_emulation.info.nb_enb_local));
eNB_inst++) {
if (oai_emulation.info.cli_start_enb[eNB_inst] != 0) {
/*
LOG_D(EMU,
"PHY procedures eNB %d for frame %d, subframe %d TDD %d/%d Nid_cell %d\n",
eNB_inst,
frame % MAX_FRAME_NUMBER,
sf,
PHY_vars_eNB_g[eNB_inst][0]->frame_parms.frame_type,
PHY_vars_eNB_g[eNB_inst][0]->frame_parms.tdd_config,
PHY_vars_eNB_g[eNB_inst][0]->frame_parms.Nid_cell);
*/
#ifdef OPENAIR2
//Application: traffic gen
update_otg_eNB (eNB_inst, oai_emulation.info.time_ms);
//IP/OTG to PDCP and PDCP to IP operation
// pdcp_run (frame, 1, 0, eNB_inst); //PHY_vars_eNB_g[eNB_id]->Mod_id
#endif
#ifdef PRINT_STATS
if((sf==9) && frame%10==0)
if(eNB_avg_thr)
fprintf(eNB_avg_thr,"%d %d\n",RC.eNB[eNB_inst][0]->proc.proc_rxtx[sf&1].frame_tx,
(RC.eNB[eNB_inst][0]->total_system_throughput)/((RC.eNB[eNB_inst][0]->proc.proc_rxtx[sf&1].frame_tx+1)*10));
/*
if (eNB_stats[eNB_inst]) {
len = dump_eNB_stats(RC.eNB[eNB_inst][0], stats_buffer, 0);
rewind (eNB_stats[eNB_inst]);
fwrite (stats_buffer, 1, len, eNB_stats[eNB_inst]);
fflush(eNB_stats[eNB_inst]);
}
*/
#ifdef OPENAIR2
/*
if (eNB_l2_stats) {
len = dump_eNB_l2_stats (stats_buffer, 0);
rewind (eNB_l2_stats);
fwrite (stats_buffer, 1, len, eNB_l2_stats);
fflush(eNB_l2_stats);
}
*/
#endif
#endif
}
}// eNB_inst loop
#if defined(ENABLE_ITTI)
log_set_instance_type (LOG_INSTANCE_UE);
#endif
if ((sf == 0) && ((frame % MAX_FRAME_NUMBER) == 0) && (abstraction_flag == 0)
&& (oai_emulation.info.n_frames == 1)) {
write_output ("dlchan0.m",
"dlch0",
&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[0][0][0]),
(6
* (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
1, 1);
write_output ("dlchan1.m",
"dlch1",
&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[1][0][0]),
(6
* (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
1, 1);
write_output ("dlchan2.m",
"dlch2",
&(PHY_vars_UE_g[0][0]->common_vars.common_vars_rx_data_per_thread[0].dl_ch_estimates[2][0][0]),
(6
* (PHY_vars_UE_g[0][0]->frame_parms.ofdm_symbol_size)),
1, 1);
write_output ("pbch_rxF_comp0.m",
"pbch_comp0",
PHY_vars_UE_g[0][0]->pbch_vars[0]->rxdataF_comp[0],
6 * 12 * 4, 1, 1);
write_output ("pbch_rxF_llr.m", "pbch_llr",
PHY_vars_UE_g[0][0]->pbch_vars[0]->llr,
(PHY_vars_UE_g[0][0]->frame_parms.Ncp == 0) ? 1920 : 1728, 1,
4);
}
stop_meas (&oaisim_stats_f);
} // SUBFRAME INNER PART
}
update_ocm ();
/*
if ((frame >= 10) && (frame <= 11) && (abstraction_flag == 0)
#ifdef PROC
&&(Channel_Flag==0)
#endif
) {
sprintf (fname, "UEtxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "txs%d", frame % MAX_FRAME_NUMBER);
write_output (fname,
vname,
PHY_vars_UE_g[0][0]->common_vars.txdata[0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
sprintf (fname, "eNBtxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "txs%d", frame % MAX_FRAME_NUMBER);
write_output (fname,
vname,
PHY_vars_eNB_g[0][0]->common_vars.txdata[0][0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
sprintf (fname, "eNBtxsigF%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "txsF%d", frame % MAX_FRAME_NUMBER);
write_output (fname,
vname,
PHY_vars_eNB_g[0][0]->common_vars.txdataF[0][0],
PHY_vars_eNB_g[0][0]->frame_parms.symbols_per_tti
* PHY_vars_eNB_g[0][0]->frame_parms.ofdm_symbol_size,
1, 1);
sprintf (fname, "UErxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "rxs%d", frame % MAX_FRAME_NUMBER);
write_output (fname,
vname,
PHY_vars_UE_g[0][0]->common_vars.rxdata[0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
sprintf (fname, "eNBrxsig%d.m", frame % MAX_FRAME_NUMBER);
sprintf (vname, "rxs%d", frame % MAX_FRAME_NUMBER);
write_output (fname,
vname,
PHY_vars_eNB_g[0][0]->common_vars.rxdata[0][0],
PHY_vars_UE_g[0][0]->frame_parms.samples_per_tti
* 10,
1, 1);
}
*/
//#ifdef XFORMS
if (xforms==1) {
eNB_inst = 0;
for (UE_inst = 0; UE_inst < NB_UE_INST; UE_inst++) {
for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
phy_scope_UE(form_ue[CC_id][UE_inst],
PHY_vars_UE_g[UE_inst][CC_id],
eNB_inst,
UE_inst,
7);
}
if (RC.eNB && RC.eNB[eNB_inst] && RC.eNB[eNB_inst][0] )
phy_scope_eNB(form_enb[UE_inst],
RC.eNB[eNB_inst][0],
UE_inst);
}
}
//#endif
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
if ((frame % MAX_FRAME_NUMBER == config_frames[0]) || (frame % MAX_FRAME_NUMBER == config_frames[1]) || (frame % MAX_FRAME_NUMBER == config_frames[2]) || (frame % MAX_FRAME_NUMBER == config_frames[3])) {
smbv_frame_cnt++;
}
#endif
} // frame loop
stop_meas (&oaisim_stats);
oai_shutdown ();
#ifdef PRINT_STATS
for (UE_inst=0; UE_inst<NB_UE_INST; UE_inst++) {
if (UE_stats[UE_inst])
fclose (UE_stats[UE_inst]);
if(UE_stats_th[UE_inst])
fclose (UE_stats_th[UE_inst]);
}
for (eNB_inst=0; eNB_inst<NB_eNB_INST; eNB_inst++) {
if (eNB_stats[eNB_inst])
fclose (eNB_stats[eNB_inst]);
}
if (eNB_avg_thr)
fclose (eNB_avg_thr);
if (eNB_l2_stats)
fclose (eNB_l2_stats);
#endif
#if defined(ENABLE_ITTI)
itti_terminate_tasks(TASK_L2L1);
#endif
return NULL;
}
/*
* The following two functions are meant to restart *the lte-softmodem* and are
* here to make oaisim compile. A restart command from the controller will be
* ignored in oaisim.
*/
int stop_L1L2(int enb_id)
{
LOG_W(FLEXRAN_AGENT, "stop_L1L2() not supported in oaisim\n");
return 0;
}
int restart_L1L2(int enb_id)
{
LOG_W(FLEXRAN_AGENT, "restart_L1L2() not supported in oaisim\n");
return 0;
}
#if T_TRACER
int T_wait = 1; /* by default we wait for the tracer */
int T_port = 2021; /* default port to listen to to wait for the tracer */
int T_dont_fork = 0; /* default is to fork, see 'T_init' to understand */
#endif
void wait_RUs(void)
{
int i;
// wait for all RUs to be configured over fronthaul
pthread_mutex_lock(&RC.ru_mutex);
while (RC.ru_mask>0) {
pthread_cond_wait(&RC.ru_cond,&RC.ru_mutex);
}
// copy frame parameters from RU to UEs
for (i=0;i<NB_UE_INST;i++) {
PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL = RC.ru[0]->frame_parms.N_RB_DL;
PHY_vars_UE_g[i][0]->frame_parms.N_RB_UL = RC.ru[0]->frame_parms.N_RB_UL;
PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_tx = 1;
PHY_vars_UE_g[i][0]->frame_parms.nb_antennas_rx = 1;
// set initially to 2, it will be revised after initial synchronization
PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB = 2;
PHY_vars_UE_g[i][0]->frame_parms.tdd_config = 1;
PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq = RC.ru[0]->frame_parms.dl_CarrierFreq;
PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq = RC.ru[0]->frame_parms.ul_CarrierFreq;
PHY_vars_UE_g[i][0]->frame_parms.eutra_band = RC.ru[0]->frame_parms.eutra_band;
LOG_I(PHY,"Initializing UE %d frame parameters from RU information: N_RB_DL %d, p %d, dl_Carrierfreq %u, ul_CarrierFreq %u, eutra_band %d\n",
i,
PHY_vars_UE_g[i][0]->frame_parms.N_RB_DL,
PHY_vars_UE_g[i][0]->frame_parms.nb_antenna_ports_eNB,
PHY_vars_UE_g[i][0]->frame_parms.dl_CarrierFreq,
PHY_vars_UE_g[i][0]->frame_parms.ul_CarrierFreq,
PHY_vars_UE_g[i][0]->frame_parms.eutra_band);
current_UE_rx_timestamp[i][0] = RC.ru[0]->frame_parms.samples_per_tti + RC.ru[0]->frame_parms.ofdm_symbol_size + RC.ru[0]->frame_parms.nb_prefix_samples0;
}
for (ru_id=0;ru_id<RC.nb_RU;ru_id++) current_ru_rx_timestamp[ru_id][0] = RC.ru[ru_id]->frame_parms.samples_per_tti;
printf("RUs are ready, let's go\n");
}
void init_UE(int,int,int,int);
void init_RU(const char*);
void set_UE_defaults(int nb_ue) {
for (int UE_id = 0;UE_id<nb_ue;UE_id++) {
for (int CC_id = 0;CC_id<MAX_NUM_CCs;CC_id++) {
for (uint8_t i=0; i<RX_NB_TH_MAX; i++) {
PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[i][0]->dciFormat = 0;
PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[i][0]->agregationLevel = 0xFF;
}
PHY_vars_UE_g[UE_id][CC_id]->current_dlsch_cqi[0] = 10;
}
}
}
static void print_current_directory(void)
{
char dir[8192]; /* arbitrary size (should be big enough) */
if (getcwd(dir, 8192) == NULL)
printf("ERROR getting working directory\n");
else
printf("working directory: %s\n", dir);
}
void init_devices(void);
int main (int argc, char **argv)
{
clock_t t;
print_current_directory();
start_background_system();
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
strcpy(smbv_ip,DEFAULT_SMBV_IP);
#endif
#ifdef PROC
int node_id;
int port,Process_Flag=0,wgt,Channel_Flag=0,temp;
#endif
//default parameters
oai_emulation.info.n_frames = MAX_FRAME_NUMBER; //1024; //10;
oai_emulation.info.n_frames_flag = 0; //fixme
snr_dB = 30;
//Default values if not changed by the user in get_simulation_options();
pdcp_period = 1;
omg_period = 1;
//Clean ip rule table
for(int i =0; i<NUMBER_OF_UE_MAX; i++){
char command_line[100];
sprintf(command_line, "while ip rule del table %d; do true; done",i+201);
/* we don't care about return value from system(), but let's the
* compiler be silent, so let's do "if (XX);"
*/
if (system(command_line)) /* nothing */;
}
// start thread for log gen
log_thread_init ();
init_oai_emulation (); // to initialize everything !!!
// get command-line options
get_simulation_options (argc, argv); //Command-line options
#if T_TRACER
T_init(T_port, T_wait, T_dont_fork);
#endif
// Initialize VCD LOG module
VCD_SIGNAL_DUMPER_INIT (oai_emulation.info.vcd_file);
#if !defined(ENABLE_ITTI)
pthread_t tid;
int err;
sigset_t sigblock;
sigemptyset (&sigblock);
sigaddset (&sigblock, SIGHUP);
sigaddset (&sigblock, SIGINT);
sigaddset (&sigblock, SIGTERM);
sigaddset (&sigblock, SIGQUIT);
//sigaddset(&sigblock, SIGKILL);
if ((err = pthread_sigmask (SIG_BLOCK, &sigblock, NULL)) != 0) {
printf ("SIG_BLOCK error\n");
return -1;
}
if (pthread_create (&tid, NULL, sigh, NULL)) {
printf ("Pthread for tracing Signals is not created!\n");
return -1;
} else {
printf ("Pthread for tracing Signals is created!\n");
}
#endif
// configure oaisim with OCG
oaisim_config (); // config OMG and OCG, OPT, OTG, OLG
if (ue_connection_test == 1) {
snr_direction = -snr_step;
snr_dB = 20;
sinr_dB = -20;
}
pthread_cond_init(&sync_cond,NULL);
pthread_mutex_init(&sync_mutex, NULL);
pthread_mutex_init(&subframe_mutex, NULL);
#ifdef OPENAIR2
init_omv ();
#endif
//Before this call, NB_UE_INST and NB_eNB_INST are not set correctly
check_and_adjust_params ();
set_seed = oai_emulation.emulation_config.seed.value;
init_otg_pdcp_buffer ();
init_seed (set_seed);
init_RU(NULL);
init_devices ();
// init_openair2 ();
// init_openair0();
if (create_tasks_ue(oai_emulation.info.nb_ue_local) < 0)
exit(-1); // need a softer mode
printf("Waiting for RUs to get set up\n");
wait_RUs();
init_UE(NB_UE_INST,0,0,1);
set_UE_defaults(NB_UE_INST);
init_ocm ();
printf("Sending sync to all threads\n");
pthread_mutex_lock(&sync_mutex);
sync_var=0;
pthread_cond_broadcast(&sync_cond);
pthread_mutex_unlock(&sync_mutex);
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
smbv_init_config(smbv_fname, smbv_nframes);
smbv_write_config_from_frame_parms(smbv_fname, &PHY_vars_eNB_g[0][0]->frame_parms);
#endif
/* #if defined (FLEXRAN_AGENT_SB_IF)
flexran_agent_start();
#endif */
// add events to future event list: Currently not used
//oai_emulation.info.oeh_enabled = 1;
if (oai_emulation.info.oeh_enabled == 1)
schedule_events ();
// oai performance profiler is enabled
if (oai_emulation.info.opp_enabled == 1)
reset_opp_meas_oaisim ();
cpuf=get_cpu_freq_GHz();
init_time ();
init_slot_isr ();
t = clock ();
LOG_N(EMU,
">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU initialization done <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
#ifndef PACKAGE_VERSION
# define PACKAGE_VERSION "UNKNOWN-EXPERIMENTAL"
#endif
LOG_I(EMU, "Version: %s\n", PACKAGE_VERSION);
#if defined(ENABLE_ITTI)
// Handle signals until all tasks are terminated
itti_wait_tasks_end();
#else
if (oai_emulation.info.nb_enb_local > 0) {
eNB_app_task (NULL); // do nothing for the moment
}
l2l1_task (NULL);
#endif
t = clock () - t;
LOG_I(EMU, "Duration of the simulation: %f seconds\n",
((float) t) / CLOCKS_PER_SEC);
LOG_N(EMU,
">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU Ending <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
raise (SIGINT);
// oai_shutdown ();
return (0);
}
void
reset_opp_meas_oaisim (void)
{
uint8_t eNB_id = 0, UE_id = 0;
reset_meas (&oaisim_stats);
reset_meas (&oaisim_stats_f); // frame
// init time stats here (including channel)
reset_meas (&dl_chan_stats);
reset_meas (&ul_chan_stats);
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[0]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[1]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[0]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[1]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_tx);
// reset_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_demod_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->rx_dft_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_channel_estimation_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_freq_offset_estimation_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[0]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[1]);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_rate_unmatching_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_turbo_decoding_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_deinterleaving_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_llr_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_unscrambling_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_init_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_alpha_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_beta_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_gamma_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_ext_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl1_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl2_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->tx_prach);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_mod_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_encoding_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_modulation_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_segmentation_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_rate_matching_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_turbo_encoding_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_interleaving_stats);
reset_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_multiplexing_stats);
/*
* L2 functions
*/
// UE MAC
reset_meas (&UE_mac_inst[UE_id].ue_scheduler); // total
reset_meas (&UE_mac_inst[UE_id].tx_ulsch_sdu); // inlcude rlc_data_req + mac header gen
reset_meas (&UE_mac_inst[UE_id].rx_dlsch_sdu); // include mac_rrc_data_ind or mac_rlc_status_ind+mac_rlc_data_ind and mac header parser
reset_meas (&UE_mac_inst[UE_id].ue_query_mch);
reset_meas (&UE_mac_inst[UE_id].rx_mch_sdu); // include rld_data_ind+ parse mch header
reset_meas (&UE_mac_inst[UE_id].rx_si); // include rlc_data_ind + mac header parser
reset_meas (&UE_pdcp_stats[UE_id].pdcp_run);
reset_meas (&UE_pdcp_stats[UE_id].data_req);
reset_meas (&UE_pdcp_stats[UE_id].data_ind);
reset_meas (&UE_pdcp_stats[UE_id].apply_security);
reset_meas (&UE_pdcp_stats[UE_id].validate_security);
reset_meas (&UE_pdcp_stats[UE_id].pdcp_ip);
reset_meas (&UE_pdcp_stats[UE_id].ip_pdcp);
}
for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
reset_meas (&RU2UE[eNB_id][UE_id][0]->random_channel);
reset_meas (&RU2UE[eNB_id][UE_id][0]->interp_time);
reset_meas (&RU2UE[eNB_id][UE_id][0]->interp_freq);
reset_meas (&RU2UE[eNB_id][UE_id][0]->convolution);
reset_meas (&UE2RU[UE_id][eNB_id][0]->random_channel);
reset_meas (&UE2RU[UE_id][eNB_id][0]->interp_time);
reset_meas (&UE2RU[UE_id][eNB_id][0]->interp_freq);
reset_meas (&UE2RU[UE_id][eNB_id][0]->convolution);
}
reset_meas (&RC.eNB[eNB_id][0]->phy_proc);
reset_meas (&RC.eNB[eNB_id][0]->phy_proc_rx);
reset_meas (&RC.eNB[eNB_id][0]->phy_proc_tx);
reset_meas (&RC.eNB[eNB_id][0]->rx_prach);
reset_meas (&RC.eNB[eNB_id][0]->ofdm_mod_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_encoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_modulation_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_scrambling_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_rate_matching_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_turbo_encoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->dlsch_interleaving_stats);
// reset_meas (&RC.eNB[eNB_id][0]->ofdm_demod_stats);
//reset_meas(&RC.eNB[eNB_id]->rx_dft_stats);
//reset_meas(&RC.eNB[eNB_id]->ulsch_channel_estimation_stats);
//reset_meas(&RC.eNB[eNB_id]->ulsch_freq_offset_estimation_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_decoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_demodulation_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_rate_unmatching_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_turbo_decoding_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_deinterleaving_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_demultiplexing_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_llr_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_init_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_alpha_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_beta_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_gamma_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_ext_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl1_stats);
reset_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl2_stats);
#ifdef LOCALIZATION
reset_meas(&RC.eNB[eNB_id][0]->localization_stats);
#endif
/*
* L2 functions
*/
// eNB MAC
reset_meas (&RC.mac[eNB_id]->eNB_scheduler); // total
reset_meas (&RC.mac[eNB_id]->schedule_si); // only schedule + tx
reset_meas (&RC.mac[eNB_id]->schedule_ra); // only ra
reset_meas (&RC.mac[eNB_id]->schedule_ulsch); // onlu ulsch
reset_meas (&RC.mac[eNB_id]->fill_DLSCH_dci); // only dci
reset_meas (&RC.mac[eNB_id]->schedule_dlsch_preprocessor); // include rlc_data_req + MAC header gen
reset_meas (&RC.mac[eNB_id]->schedule_dlsch); // include rlc_data_req + MAC header gen + pre-processor
reset_meas (&RC.mac[eNB_id]->schedule_mch); // only embms
reset_meas (&RC.mac[eNB_id]->rx_ulsch_sdu); // include rlc_data_ind + mac header parser
reset_meas (&eNB_pdcp_stats[eNB_id].pdcp_run);
reset_meas (&eNB_pdcp_stats[eNB_id].data_req);
reset_meas (&eNB_pdcp_stats[eNB_id].data_ind);
reset_meas (&eNB_pdcp_stats[eNB_id].apply_security);
reset_meas (&eNB_pdcp_stats[eNB_id].validate_security);
reset_meas (&eNB_pdcp_stats[eNB_id].pdcp_ip);
reset_meas (&eNB_pdcp_stats[eNB_id].ip_pdcp);
}
}
void
print_opp_meas_oaisim (void)
{
uint8_t eNB_id = 0, UE_id = 0;
print_meas (&oaisim_stats, "[OAI][total_exec_time]", &oaisim_stats,
&oaisim_stats);
print_meas (&oaisim_stats_f, "[OAI][SF_exec_time]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&dl_chan_stats, "[DL][chan_stats]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&ul_chan_stats, "[UL][chan_stats]", &oaisim_stats,
&oaisim_stats_f);
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
for (ru_id = 0; ru_id < NB_RU; ru_id++) {
print_meas (&RU2UE[ru_id][UE_id][0]->random_channel,
"[DL][random_channel]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RU2UE[ru_id][UE_id][0]->interp_time,
"[DL][interp_time]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RU2UE[ru_id][UE_id][0]->interp_freq,
"[DL][interp_freq]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RU2UE[ru_id][UE_id][0]->convolution,
"[DL][convolution]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->random_channel,
"[UL][random_channel]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->interp_time,
"[UL][interp_time]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->interp_freq,
"[UL][interp_freq]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE2RU[UE_id][ru_id][0]->convolution,
"[UL][convolution]", &oaisim_stats, &oaisim_stats_f);
}
}
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[0], "[UE][total_phy_proc[0]]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc[1], "[UE][total_phy_proc[1]]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[0],
"[UE][total_phy_proc_rx[0]]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_rx[1],
"[UE][total_phy_proc_rx[1]]", &oaisim_stats, &oaisim_stats_f);
// print_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_demod_stats,
// "[UE][ofdm_demod]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->rx_dft_stats, "[UE][rx_dft]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_channel_estimation_stats,
"[UE][channel_est]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_freq_offset_estimation_stats,
"[UE][freq_offset]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_llr_stats, "[UE][llr]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_unscrambling_stats,
"[UE][unscrambling]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[0],
"[UE][decoding[0]]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_decoding_stats[1],
"[UE][decoding[1]]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_rate_unmatching_stats,
"[UE][rate_unmatching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_deinterleaving_stats,
"[UE][deinterleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_turbo_decoding_stats,
"[UE][turbo_decoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_init_stats,
"[UE][ |_tc_init]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_alpha_stats,
"[UE][ |_tc_alpha]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_beta_stats,
"[UE][ |_tc_beta]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_gamma_stats,
"[UE][ |_tc_gamma]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_ext_stats,
"[UE][ |_tc_ext]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl1_stats,
"[UE][ |_tc_intl1]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->dlsch_tc_intl2_stats,
"[UE][ |_tc_intl2]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->phy_proc_tx,
"[UE][total_phy_proc_tx]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ofdm_mod_stats, "[UE][ofdm_mod]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_modulation_stats,
"[UE][modulation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_encoding_stats,
"[UE][encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_segmentation_stats,
"[UE][segmentation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_rate_matching_stats,
"[UE][rate_matching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_turbo_encoding_stats,
"[UE][turbo_encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_interleaving_stats,
"[UE][interleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&PHY_vars_UE_g[UE_id][0]->ulsch_multiplexing_stats,
"[UE][multiplexing]", &oaisim_stats, &oaisim_stats_f);
}
for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
print_meas (&RC.eNB[eNB_id][0]->phy_proc,
"[eNB][total_phy_proc]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->phy_proc_tx,
"[eNB][total_phy_proc_tx]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ofdm_mod_stats,
"[eNB][ofdm_mod]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_modulation_stats,
"[eNB][modulation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_scrambling_stats,
"[eNB][scrambling]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_encoding_stats,
"[eNB][encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_interleaving_stats,
"[eNB][|_interleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_rate_matching_stats,
"[eNB][|_rate_matching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->dlsch_turbo_encoding_stats,
"[eNB][|_turbo_encoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->phy_proc_rx,
"[eNB][total_phy_proc_rx]", &oaisim_stats, &oaisim_stats_f);
// print_meas (&RC.eNB[eNB_id][0]->ofdm_demod_stats,
// "[eNB][ofdm_demod]", &oaisim_stats, &oaisim_stats_f);
//print_meas(&RC.eNB[eNB_id][0]->ulsch_channel_estimation_stats,"[eNB][channel_est]");
//print_meas(&RC.eNB[eNB_id][0]->ulsch_freq_offset_estimation_stats,"[eNB][freq_offset]");
//print_meas(&RC.eNB[eNB_id][0]->rx_dft_stats,"[eNB][rx_dft]");
print_meas (&RC.eNB[eNB_id][0]->ulsch_demodulation_stats,
"[eNB][demodulation]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_decoding_stats,
"[eNB][decoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_deinterleaving_stats,
"[eNB][|_deinterleaving]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_demultiplexing_stats,
"[eNB][|_demultiplexing]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_rate_unmatching_stats,
"[eNB][|_rate_unmatching]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_turbo_decoding_stats,
"[eNB][|_turbo_decoding]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_init_stats,
"[eNB][ |_tc_init]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_alpha_stats,
"[eNB][ |_tc_alpha]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_beta_stats,
"[eNB][ |_tc_beta]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_gamma_stats,
"[eNB][ |_tc_gamma]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_ext_stats,
"[eNB][ |_tc_ext]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl1_stats,
"[eNB][ |_tc_intl1]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->ulsch_tc_intl2_stats,
"[eNB][ |_tc_intl2]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.eNB[eNB_id][0]->rx_prach, "[eNB][rx_prach]",
&oaisim_stats, &oaisim_stats_f);
#ifdef LOCALIZATION
print_meas(&RC.eNB[eNB_id][0]->localization_stats, "[eNB][LOCALIZATION]",&oaisim_stats,&oaisim_stats_f);
#endif
}
for (UE_id = 0; UE_id < NB_UE_INST; UE_id++) {
print_meas (&UE_mac_inst[UE_id].ue_scheduler, "[UE][mac_scheduler]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].tx_ulsch_sdu, "[UE][tx_ulsch_sdu]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].rx_dlsch_sdu, "[UE][rx_dlsch_sdu]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].ue_query_mch, "[UE][query_MCH]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].rx_mch_sdu, "[UE][rx_mch_sdu]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_mac_inst[UE_id].rx_si, "[UE][rx_si]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].pdcp_run, "[UE][total_pdcp_run]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].data_req, "[UE][DL][pdcp_data_req]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].data_ind, "[UE][UL][pdcp_data_ind]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].apply_security,
"[UE][DL][apply_security]", &oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].validate_security,
"[UE][UL][validate_security]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].ip_pdcp, "[UE][DL][ip_pdcp]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&UE_pdcp_stats[UE_id].pdcp_ip, "[UE][UL][pdcp_ip]",
&oaisim_stats, &oaisim_stats_f);
}
for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) {
print_meas (&RC.mac[eNB_id]->eNB_scheduler, "[eNB][mac_scheduler]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_si, "[eNB][DL][SI]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_ra, "[eNB][DL][RA]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->fill_DLSCH_dci,
"[eNB][DL/UL][fill_DCI]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_dlsch_preprocessor,
"[eNB][DL][preprocessor]", &oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_dlsch,
"[eNB][DL][schedule_tx_dlsch]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_mch, "[eNB][DL][mch]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->schedule_ulsch, "[eNB][UL][ULSCH]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&RC.mac[eNB_id]->rx_ulsch_sdu,
"[eNB][UL][rx_ulsch_sdu]", &oaisim_stats, &oaisim_stats_f);
print_meas (&eNB_pdcp_stats[eNB_id].pdcp_run, "[eNB][pdcp_run]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&eNB_pdcp_stats[eNB_id].data_req,
"[eNB][DL][pdcp_data_req]", &oaisim_stats, &oaisim_stats_f);
print_meas (&eNB_pdcp_stats[eNB_id].data_ind,
"[eNB][UL][pdcp_data_ind]", &oaisim_stats, &oaisim_stats_f);
print_meas (&eNB_pdcp_stats[eNB_id].apply_security,
"[eNB][DL][apply_security]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&eNB_pdcp_stats[eNB_id].validate_security,
"[eNB][UL][validate_security]", &oaisim_stats,
&oaisim_stats_f);
print_meas (&eNB_pdcp_stats[eNB_id].ip_pdcp, "[eNB][DL][ip_pdcp]",
&oaisim_stats, &oaisim_stats_f);
print_meas (&eNB_pdcp_stats[eNB_id].pdcp_ip, "[eNB][UL][pdcp_ip]",
&oaisim_stats, &oaisim_stats_f);
}
}
#if !defined(ENABLE_ITTI)
static void *
sigh (void *arg)
{
int signum;
sigset_t sigcatch;
sigemptyset (&sigcatch);
sigaddset (&sigcatch, SIGHUP);
sigaddset (&sigcatch, SIGINT);
sigaddset (&sigcatch, SIGTERM);
sigaddset (&sigcatch, SIGQUIT);
for (;;) {
sigwait (&sigcatch, &signum);
//sigwait(&sigblock, &signum);
switch (signum) {
case SIGHUP:
case SIGINT:
case SIGTERM:
case SIGQUIT:
fprintf (stderr, "received signal %d \n", signum);
// no need for mutx: when ITTI not used, this variable is only accessed by this function
l2l1_state = L2L1_TERMINATED;
break;
default:
fprintf (stderr, "Unexpected signal %d \n", signum);
exit (-1);
break;
}
}
pthread_exit (NULL);
}
#endif /* !defined(ENABLE_ITTI) */
void
oai_shutdown (void)
{
static int done = 0;
if (done)
return;
free (otg_pdcp_buffer);
otg_pdcp_buffer = 0;
#ifdef SMBV
// Rohde&Schwarz SMBV100A vector signal generator
if (config_smbv) {
smbv_send_config (smbv_fname,smbv_ip);
}
#endif
//Perform KPI measurements
if (oai_emulation.info.otg_enabled == 1){
LOG_N(EMU,"calling OTG kpi gen .... \n");
kpi_gen ();
}
if (oai_emulation.info.opp_enabled == 1)
print_opp_meas_oaisim ();
#ifdef PROC
if (abstraction_flag == 0 && Channel_Flag==0 && Process_Flag==0)
#else
if (abstraction_flag == 0)
#endif
{
/*
#ifdef IFFT_FPGA
free(txdataF2[0]);
free(txdataF2[1]);
free(txdataF2);
free(txdata[0]);
free(txdata[1]);
free(txdata);
#endif
*/
/*
for (int i = 0; i < 2; i++) {
free (s_re[i]);
free (s_im[i]);
free (r_re[i]);
free (r_im[i]);
}
free (s_re);
free (s_im);
free (r_re);
free (r_im);
s_re = 0;
s_im = 0;
r_re = 0;
r_im = 0;*/
lte_sync_time_free ();
}
// added for PHY abstraction
if (oai_emulation.info.ocm_enabled == 1) {
for (eNB_inst = 0; eNB_inst < NUMBER_OF_eNB_MAX; eNB_inst++) {
free (enb_data[eNB_inst]);
enb_data[eNB_inst] = 0;
}
for (UE_inst = 0; UE_inst < NUMBER_OF_UE_MAX; UE_inst++) {
free (ue_data[UE_inst]);
ue_data[UE_inst] = 0;
}
} //End of PHY abstraction changes
// stop OMG
stop_mobility_generator (omg_param_list); //omg_param_list.mobility_type
#ifdef OPENAIR2
if (oai_emulation.info.omv_enabled == 1)
omv_end (pfd[1], omv_data);
#endif
if ((oai_emulation.info.ocm_enabled == 1) && (ethernet_flag == 0)
&& (ShaF != NULL)) {
destroyMat (ShaF, map1, map2);
ShaF = 0;
}
if (opt_enabled == 1)
terminate_opt ();
if (oai_emulation.info.cli_enabled)
cli_server_cleanup ();
for (int i = 0; i < NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; i++)
if (oai_emulation.info.oai_ifup[i] == 1) {
char interfaceName[8];
snprintf (interfaceName, sizeof(interfaceName), "oai%d", i);
bringInterfaceUp (interfaceName, 0);
}
log_thread_finalize ();
logClean ();
VCD_SIGNAL_DUMPER_CLOSE ();
done = 1; // prevent next invokation of this function
LOG_N(EMU,
">>>>>>>>>>>>>>>>>>>>>>>>>>> OAIEMU shutdown <<<<<<<<<<<<<<<<<<<<<<<<<<\n\n");
}
eNB_MAC_INST*
get_eNB_mac_inst (module_id_t module_idP)
{
return (RC.mac[module_idP]);
}
OAI_Emulation*
get_OAI_emulation ()
{
return &oai_emulation;
}
// dummy function declarations
void *rrc_enb_task(void *args_p)
{
return NULL;
}
| {
"alphanum_fraction": 0.6596936333,
"avg_line_length": 33.8208310847,
"ext": "c",
"hexsha": "0008ba3bbde128740f20be36289ad2b419d018e9",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a082c3e8af06cd7583c003a69ec517eb73d175b3",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "davidraditya/OAI-Powder",
"max_forks_repo_path": "targets/SIMU/USER/oaisim.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a082c3e8af06cd7583c003a69ec517eb73d175b3",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "davidraditya/OAI-Powder",
"max_issues_repo_path": "targets/SIMU/USER/oaisim.c",
"max_line_length": 471,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a082c3e8af06cd7583c003a69ec517eb73d175b3",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "davidraditya/OAI-Powder",
"max_stars_repo_path": "targets/SIMU/USER/oaisim.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 19663,
"size": 62670
} |
#pragma once
#include <math.h>
#include <stdint.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
double nn_sigmoid(const double x);
double nn_sigmoid_prime(const double x);
gsl_vector * nn_ones_v(const size_t n);
gsl_vector * nn_sigmoid_v(const gsl_vector *x);
gsl_vector * nn_sigmoid_prime_v(const gsl_vector *x);
gsl_matrix * nn_ones_m(const size_t n, const size_t m);
gsl_matrix * nn_sigmoid_m(const gsl_matrix *x);
gsl_matrix * nn_sigmoid_prime_m(const gsl_matrix *x);
| {
"alphanum_fraction": 0.7745901639,
"avg_line_length": 25.6842105263,
"ext": "h",
"hexsha": "7803ae8e20ea0f8054b374ab89f3c6cef3401931",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "250995db0e9d555cc51dfda2f0ee6720c15fc4c4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mygulamali/neural-net",
"max_forks_repo_path": "include/nn_math.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "250995db0e9d555cc51dfda2f0ee6720c15fc4c4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mygulamali/neural-net",
"max_issues_repo_path": "include/nn_math.h",
"max_line_length": 55,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "250995db0e9d555cc51dfda2f0ee6720c15fc4c4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mygulamali/neural-net",
"max_stars_repo_path": "include/nn_math.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 137,
"size": 488
} |
/* specfunc/test_gamma.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Author: G. Jungman */
#include <config.h>
#include <gsl/gsl_test.h>
#include <gsl/gsl_sf.h>
#include "test_sf.h"
int test_gamma(void)
{
gsl_sf_result r;
gsl_sf_result r1, r2;
double sgn;
int s = 0;
TEST_SF(s, gsl_sf_lngamma_e, (-0.1, &r), 2.368961332728788655 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (-1.0/256.0, &r), 5.547444766967471595 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (1.0e-08, &r), 18.420680738180208905 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (0.1, &r), 2.252712651734205 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (1.0 + 1.0/256.0, &r), -0.0022422226599611501448 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (2.0 + 1.0/256.0, &r), 0.0016564177556961728692 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (100.0, &r), 359.1342053695753 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (-1.0-1.0/65536.0, &r), 11.090348438090047844 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (-1.0-1.0/268435456.0, &r), 19.408121054103474300 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (-100.5, &r), -364.9009683094273518 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lngamma_e, (-100-1.0/65536.0, &r), -352.6490910117097874 , TEST_TOL0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (0.7, &r, &sgn), 0.26086724653166651439, TEST_TOL1, 1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (0.1, &r, &sgn), 2.2527126517342059599, TEST_TOL0, 1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (-0.1, &r, &sgn), 2.368961332728788655, TEST_TOL0, -1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (-1.0-1.0/65536.0, &r, &sgn), 11.090348438090047844, TEST_TOL0, 1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (-2.0-1.0/256.0, &r, &sgn), 4.848447725860607213, TEST_TOL0, -1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (-2.0-1.0/65536.0, &r, &sgn), 10.397193628164674967, TEST_TOL0, -1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (-3.0-1.0/8.0, &r, &sgn), 0.15431112768404182427, TEST_TOL2, 1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lngamma_sgn_e, (-100.5, &r, &sgn), -364.9009683094273518, TEST_TOL0, -1.0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (1.0 + 1.0/4096.0, &r), 0.9998591371459403421 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (1.0 + 1.0/32.0, &r), 0.9829010992836269148 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (2.0 + 1.0/256.0, &r), 1.0016577903733583299 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (9.0, &r), 40320.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (10.0, &r), 362880.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (100.0, &r), 9.332621544394415268e+155 , TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (170.0, &r), 4.269068009004705275e+304 , TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (-10.5, &r), -2.640121820547716316e-07 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_e, (-11.25, &r), 6.027393816261931672e-08 , TEST_TOL0, GSL_SUCCESS); /* exp()... not my fault */
TEST_SF(s, gsl_sf_gamma_e, (-1.0+1.0/65536.0, &r), -65536.42280587818970 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (1.0e-08, &r), 3989.423555759890865 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (1.0e-05, &r), 126.17168469882690233 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (0.001, &r), 12.708492464364073506 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (1.5, &r), 1.0563442442685598666 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (3.0, &r), 1.0280645179187893045 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (9.0, &r), 1.0092984264218189715 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (11.0, &r), 1.0076024283104962850 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (100.0, &r), 1.0008336778720121418 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (1.0e+05, &r), 1.0000008333336805529 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammastar_e, (1.0e+20, &r), 1.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammainv_e, (10.0, &r), 1.0/362880.0, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammainv_e, (100.0, &r), 1.0715102881254669232e-156, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammainv_e, (-10.5, &r), -1.0/2.640121820547716316e-07, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammainv_e, (-11.25, &r), 1.0/6.027393816261931672e-08, TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gammainv_e, (-1.0+1.0/65536.0, &r), -1.0/65536.42280587818970 , TEST_TOL1, GSL_SUCCESS);
TEST_SF_2(s, gsl_sf_lngamma_complex_e, (5.0, 2.0, &r1, &r2),
2.7487017561338026749, TEST_TOL0,
3.0738434100497007915, TEST_TOL0,
GSL_SUCCESS);
TEST_SF_2(s, gsl_sf_lngamma_complex_e, (100.0, 100.0, &r1, &r2),
315.07804459949331323, TEST_TOL1,
2.0821801804113110099, TEST_TOL3,
GSL_SUCCESS);
TEST_SF_2(s, gsl_sf_lngamma_complex_e, (100.0, -1000.0, &r1, &r2),
-882.3920483010362817000, TEST_TOL1,
-2.1169293725678813270, TEST_TOL3,
GSL_SUCCESS);
TEST_SF_2(s, gsl_sf_lngamma_complex_e, (-100.0, -1.0, &r1, &r2),
-365.0362469529239516000, TEST_TOL1,
-3.0393820262864361140, TEST_TOL1,
GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (10, 1.0/1048576.0, &r), 1.7148961854776073928e-67 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (10, 1.0/1024.0, &r), 2.1738891788497900281e-37 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (10, 1.0, &r), 2.7557319223985890653e-07 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (10, 5.0, &r), 2.6911444554673721340 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (10, 500.0, &r), 2.6911444554673721340e+20 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (100, 100.0, &r), 1.0715102881254669232e+42 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (1000, 200.0, &r), 2.6628790558154746898e-267 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_taylorcoeff_e, (1000, 500.0, &r), 2.3193170139740855074e+131 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_fact_e, (0, &r), 1.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_fact_e, (1, &r), 1.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_fact_e, (7, &r), 5040.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_fact_e, (33, &r), 8.683317618811886496e+36 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_doublefact_e, (0, &r), 1.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_doublefact_e, (1, &r), 1.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_doublefact_e, (7, &r), 105.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_doublefact_e, (33, &r), 6.332659870762850625e+18 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnfact_e, (0, &r), 0.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnfact_e, (1, &r), 0.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnfact_e, (7, &r), 8.525161361065414300 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnfact_e, (33, &r), 85.05446701758151741 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lndoublefact_e, (0, &r), 0.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lndoublefact_e, (7, &r), 4.653960350157523371 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lndoublefact_e, (33, &r), 43.292252022541719660 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lndoublefact_e, (34, &r), 45.288575519655959140 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lndoublefact_e, (1034, &r), 3075.6383796271197707 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lndoublefact_e, (1035, &r), 3078.8839081731809169 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnchoose_e, (7,3, &r), 3.555348061489413680 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnchoose_e, (5,2, &r), 2.302585092994045684 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_choose_e, (7,3, &r), 35.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_choose_e, (5,2, &r), 10.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_choose_e, (500,200, &r), 5.054949849935532221e+144 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnpoch_e, (5, 1.0/65536.0, &r), 0.000022981557571259389129, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnpoch_e, (5, 1.0/256.0, &r), 0.005884960217985189004, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnpoch_e, (7,3, &r), 6.222576268071368616, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnpoch_e, (5,2, &r), 3.401197381662155375, TEST_TOL0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lnpoch_sgn_e, (-4.5, 0.25, &r, &sgn), 0.7430116475119920117, TEST_TOL1, 1.0, GSL_SUCCESS);
TEST_SF_SGN(s, gsl_sf_lnpoch_sgn_e, (-4.5, 1.25, &r, &sgn), 2.1899306304483174731, TEST_TOL1, -1.0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_poch_e, (7,3, &r), 504.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_poch_e, (5,2, &r), 30.0 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_poch_e, (5,1.0/256.0, &r), 1.0059023106151364982 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_pochrel_e, (7,3, &r), 503.0/3.0, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_pochrel_e, (5,2, &r), 29.0/2.0, TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_pochrel_e, (5,0.01, &r), 1.5186393661368275330, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_pochrel_e, (-5.5,0.01, &r), 1.8584945633829063516, TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_pochrel_e, (-5.5,-1.0/8.0, &r), 1.0883319303552135488, TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_pochrel_e, (-5.5,-1.0/256.0, &r), 1.7678268037726177453, TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_pochrel_e, (-5.5,-11.0, &r), 0.09090909090939652475, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (0.001, 0.001, &r), 0.9936876467088602902, TEST_TOL0, GSL_SUCCESS) ;
TEST_SF(s, gsl_sf_gamma_inc_P_e, (0.001, 1.0, &r), 0.9997803916424144436, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (0.001, 10.0, &r), 0.9999999958306921828, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (1.0, 0.001, &r), 0.0009995001666250083319, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (1.0, 1.01, &r), 0.6357810204284766802, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (1.0, 10.0, &r), 0.9999546000702375151, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (10.0, 10.01, &r), 0.5433207586693410570, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (10.0, 20.0, &r), 0.9950045876916924128, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (1000.0, 1000.1, &r), 0.5054666401440661753, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (1000.0, 2000.0, &r), 1.0, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (0.001, 0.001, &r), 0.006312353291139709793, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (0.001, 1.0, &r), 0.00021960835758555639171, TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (0.001, 2.0, &r), 0.00004897691783098147880, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (0.001, 5.0, &r), 1.1509813397308608541e-06, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (1.0, 0.001, &r), 0.9990004998333749917, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (1.0, 1.01, &r), 0.3642189795715233198, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (1.0, 10.0, &r), 0.00004539992976248485154, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (10.0, 10.01, &r), 0.4566792413306589430, TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (10.0, 100.0, &r), 1.1253473960842733885e-31, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (1000.0, 1000.1, &r), 0.4945333598559338247, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (1000.0, 2000.0, &r), 6.847349459614753180e-136, TEST_TOL2, GSL_SUCCESS);
/* designed to trap the a-x=1 problem */
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (100, 99.0, &r), 0.5266956696005394, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_Q_e, (200, 199.0, &r), 0.5188414119121281, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (100, 99.0, &r), 0.4733043303994607, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_gamma_inc_P_e, (200, 199.0, &r), 0.4811585880878718, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0e-8, 1.0e-8, &r), 19.113827924512310617 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0e-8, 0.01, &r), 18.420681743788563403 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0e-8, 1.0, &r), 18.420680743952365472 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0e-8, 10.0, &r), 18.420680715662683009 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0e-8, 1000.0, &r), 18.420680669107656949 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (0.1, 0.1, &r), 2.9813614810376273949 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (0.1, 1.0, &r), 2.3025850929940456840 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (0.1, 100.0, &r), 1.7926462324527931217 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (0.1, 1000, &r), 1.5619821298353164928 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0, 1.00025, &r), -0.0002499687552073570, TEST_TOL4, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0, 1.01, &r), -0.009950330853168082848 , TEST_TOL3, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (1.0, 1000.0, &r), -6.907755278982137052 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (100.0, 100.0, &r), -139.66525908670663927 , TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (100.0, 1000.0, &r), -336.4348576477366051 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_lnbeta_e, (100.0, 1.0e+8, &r), -1482.9339185256447309 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_e, (1.0, 1.0, &r), 1.0 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_e, (1.0, 1.001, &r), 0.9990009990009990010 , TEST_TOL0, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_e, (1.0, 5.0, &r), 0.2 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_e, (1.0, 100.0, &r), 0.01 , TEST_TOL1, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_e, (10.0, 100.0, &r), 2.3455339739604649879e-15 , TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (1.0, 1.0, 0.0, &r), 0.0, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (1.0, 1.0, 1.0, &r), 1.0, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (0.1, 0.1, 1.0, &r), 1.0, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 1.0, 1.0, 0.5, &r), 0.5, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 0.1, 1.0, 0.5, &r), 0.9330329915368074160, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (10.0, 1.0, 0.5, &r), 0.0009765625000000000000, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (50.0, 1.0, 0.5, &r), 8.881784197001252323e-16, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 1.0, 0.1, 0.5, &r), 0.06696700846319258402, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 1.0, 10.0, 0.5, &r), 0.99902343750000000000, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 1.0, 50.0, 0.5, &r), 0.99999999999999911180, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 1.0, 1.0, 0.1, &r), 0.10, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 1.0, 2.0, 0.1, &r), 0.19, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 1.0, 2.0, 0.9, &r), 0.99, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (50.0, 60.0, 0.5, &r), 0.8309072939016694143, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (90.0, 90.0, 0.5, &r), 0.5, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, ( 500.0, 500.0, 0.6, &r), 0.9999999999157549630, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (5000.0, 5000.0, 0.4, &r), 4.518543727260666383e-91, TEST_TOL5, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (5000.0, 5000.0, 0.6, &r), 1.0, TEST_TOL2, GSL_SUCCESS);
TEST_SF(s, gsl_sf_beta_inc_e, (5000.0, 2000.0, 0.6, &r), 8.445388773903332659e-89, TEST_TOL5, GSL_SUCCESS);
return s;
}
| {
"alphanum_fraction": 0.7035403434,
"avg_line_length": 71.746835443,
"ext": "c",
"hexsha": "a6d819ba627ed3b68e656e6b438bf80b768e2930",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z",
"max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ICML14MoMCompare/spectral-learn",
"max_forks_repo_path": "code/em/treba/gsl-1.0/specfunc/test_gamma.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ICML14MoMCompare/spectral-learn",
"max_issues_repo_path": "code/em/treba/gsl-1.0/specfunc/test_gamma.c",
"max_line_length": 124,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ICML14MoMCompare/spectral-learn",
"max_stars_repo_path": "code/em/treba/gsl-1.0/specfunc/test_gamma.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z",
"num_tokens": 7360,
"size": 17004
} |
/*******************************************************************
FUNCTION NAME: interpolate - performs the interpolation to calculate
the pixel value e.g. during resampling
INPUT: interpolation - interpolation method (nearest neighbor, bilinear, sinc)
inbuf - input image buffer
nLines - number of lines (image buffer)
nSamples - number of samples per line (image buffer)
xLine - line of interest
xSample - sample position within line
weighting - weighting function to be applied (Kaiser, Hamming)
nKernel - kernel size for sinc function
*******************************************************************/
#include <assert.h>
#include <math.h>
#include <glib.h>
#include <gsl/gsl_sf_bessel.h>
#include "asf.h"
#include "asf_raster.h"
#include "float_image.h"
#define SQR(X) ((X)*(X))
// Some parameters and weights for bicubic interpolation
#define CUBE(X) ((X)*(X)*(X))
#define P(X) ( X > 0 ? X : 0 )
// For sinc interpolation, the goal is to weight source values using a
// sinc function. We want to position the peak of the sinc at the
// point of interest. The sinc filter itself will interpolate a small
// number of point, perhaps 8 or 16, for example. In order to achieve
// the desired location of the peak, we want to introduce a shift in
// the sinc function computed. However, we don't want to recompute
// the sinc function for every point to be interpolated! The solution
// is to precompute an array of slightly shifted sinc functions, and
// then choose the appropriate one for the point we are interpolating.
// For example, if we have known values for 1 and 2, and we want to
// interpolate a value for 1.2, we choose the (1.2 - 1.0) * (2 - 1) *
// NUM_SINCS sinc function to evaluate the result.
#define NUM_SINCS 512 // Number of sinc functions to compute.
// For convenience using buffered image functions
#define GET_PIXEL(x, y) float_image_get_pixel (inbuf, x, y)
#define SET_PIXEL(x, y, value) float_image_set_pixel (inbuf, x, y, value)
// Fetch pixel ii, jj from inbuf, where inbuf is taken to be an image
// nSamples wide and nLines high. If ii, jj is outside the image, a
// "reflected" value is returned. For example, these two calls will
// return the same pixel:
//
// get_pixel_with_reflection (inbuf, sample_count, line_count, -1, -2)
// get_pixel_with_reflection (inbuf, sample_count, line_count, 1, 2);
//
// If the reflected indicies are still outside the image, an exception
// is triggered.
//static float
//get_pixel_with_reflection (float *inbuf, int nSamples, int nLines, int sample,
// int line)
//{
// int ii = sample; // Convenience alias.
// int jj = line; // Convenience alias.
// // Handle reflection at image edges.
// if ( G_UNLIKELY (ii < 0) ) {
// ii = -ii;
// }
// else if ( G_UNLIKELY (ii >= nSamples) ) {
// ii = ii - (ii - nSamples + 1) - 1;
// }
// if ( G_UNLIKELY (jj < 0) ) {
// jj = -jj;
// }
// else if ( G_UNLIKELY (jj >= nLines) ) {
// jj = jj - (jj - nLines + 1) - 1;
// }
// // Now we better be in the image.
// assert (ii >= 0 && ii < nSamples);
// assert (jj >= 0 && jj < nLines);
//
// return inbuf[nSamples * jj + ii];
//}
void samples2coefficients(FloatImage *inbuf, char dimension)
{
int ii, kk;
float z = sqrt(3.0) - 2.0;
float lambda = (1.0 - z) * (1.0 - 1.0/z);
float value;
// Apply overall gain
for (ii=0; ii<inbuf->size_x; ii++)
for (kk=0; kk<inbuf->size_y; kk++) {
value = GET_PIXEL(ii,kk) * lambda;
SET_PIXEL(ii,kk,value);
}
for (kk=0; kk<inbuf->size_y; kk++) {
// Causal initialization (first pixel of line)
}
// Causal recursion
// Anticausal initialization
// Anticausal recursion
}
float interpolate(interpolate_type_t interpolation, FloatImage *inbuf, float yLine,
float xSample, weighting_type_t weighting, int sinc_points)
{
int ix, iy, ii, kk, ll, xI[4], yI[4];
float a00, a10, a01, a11;
float value, dx, dy, wx[4], wy[4], w;
/* Get closed pixel position to start from */
switch ( interpolation )
{
case NEAREST:
ix = (int) (xSample + 0.5);
iy = (int) (yLine + 0.5);
value = GET_PIXEL(ix,iy);
break;
case BILINEAR:
assert (xSample >= 0.0);
assert (yLine >= 0.0);
assert (xSample <= inbuf->size_x - 1);
assert (yLine <= inbuf->size_y - 1);
ix = floor(xSample);
iy = floor(yLine);
a00 = GET_PIXEL(ix,iy);
a10 = GET_PIXEL(ix+1,iy) - GET_PIXEL(ix,iy);
a01 = GET_PIXEL(ix,iy+1) - GET_PIXEL(ix,iy);
a11 = GET_PIXEL(ix,iy) - GET_PIXEL(ix+1,iy) - GET_PIXEL(ix,iy+1)
+ GET_PIXEL(ix+1,iy+1);
value = (a00 + a10 * (xSample - ix) + a01 * (yLine - iy)
+ a11 * (xSample - ix) * (yLine - iy));
break;
case BICUBIC:
assert (xSample >= 0.0);
assert (yLine >= 0.0);
assert (xSample <= inbuf->size_x - 1);
assert (yLine <= inbuf->size_y - 1);
ix = floor(xSample);
iy = floor(yLine);
dx = xSample - ix;
dy = yLine - iy;
// Calculating weights
for (ii=-1; ii<=2; ii++) {
wx[ii+1] = 1.0/6.0 * (CUBE(P(ii-dx+2)) - 4*CUBE(P(ii-dx+1))
+ 6*CUBE(P(ii-dx)) - 4*CUBE(P(ii-dx-1)));
wy[ii+1] = 1.0/6.0 * (CUBE(P(dy-ii+2)) - 4*CUBE(P(dy-ii+1))
+ 6*CUBE(P(dy-ii)) - 4*CUBE(P(dy-ii-1)));
}
// Get the interpolated pixel value
value = 0.0;
for (ii=-1; ii<=2; ii++)
for (kk=-1; kk<=2; kk++)
value += GET_PIXEL(ix+ii,iy+kk) * wx[ii+1] * wy[kk+1];
break;
case SPLINES:
// Determine B-Spline coefficients.
// This is a essentially a pre-filtering applied to the entire image
// that converts the image from a sample representation into a
// representation based on B-spline coefficients.
// Without this step the result would look blurry at the end.
// Convert samples to coefficients in x direction
samples2coefficients(inbuf, 'x');
// Convert samples to coefficients in y direction
samples2coefficients(inbuf, 'y');
// Calculate interpolation indices
ii = (int)floor(xSample) - 1;
kk = (int)floor(yLine) - 1;
for (ll=0; ll<=3; ll++) {
xI[ll] = ii++;
yI[ll] = kk++;
}
// Calculate interpolation weights
w = xSample - (float)xI[1];
wx[3] = (1.0/6.0)*CUBE(xSample);
wx[0] = (1.0/6.0) + (1.0/2.0)*w*(w-1.0) - wx[3];
wx[2] = w + wx[0] - 2.0*wx[3];
wx[1] = 1.0 - wx[0] - wx[2] - wx[3];
w = yLine - (float)yI[1];
wy[3] = (1.0/6.0)*CUBE(xSample);
wy[0] = (1.0/6.0) + (1.0/2.0)*w*(w-1.0) - wy[3];
wy[2] = w + wy[0] - 2.0*wy[3];
wy[1] = 1.0 - wy[0] - wy[2] - wy[3];
// Get interpolation value
value = 0.0;
for (kk=0; kk<=3; kk++) {
w = 0.0;
for (ii=0; ii<=3; ii++)
w += wx[ii] * 1;
value += wy[kk] * w;
}
break;
case SINC:
break;
default:
assert (FALSE);
break;
}
return value;
}
| {
"alphanum_fraction": 0.5755658653,
"avg_line_length": 31.8968609865,
"ext": "c",
"hexsha": "e832c1fe1dbf79b5d67a2ca40c8bea7404425406",
"lang": "C",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2020-05-15T08:01:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-04-26T18:18:33.000Z",
"max_forks_repo_head_hexsha": "c9065400a64c87be46418ab32e3a251ca2f55fd5",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "glshort/MapReady",
"max_forks_repo_path": "src/libasf_raster/interpolate.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c9065400a64c87be46418ab32e3a251ca2f55fd5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "glshort/MapReady",
"max_issues_repo_path": "src/libasf_raster/interpolate.c",
"max_line_length": 84,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c9065400a64c87be46418ab32e3a251ca2f55fd5",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "glshort/MapReady",
"max_stars_repo_path": "src/libasf_raster/interpolate.c",
"max_stars_repo_stars_event_max_datetime": "2021-07-28T01:51:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-12-31T05:33:28.000Z",
"num_tokens": 2248,
"size": 7113
} |
#pragma once
#include "zerrors.h"
#include <string>
#include <vector>
#include <numeric>
#include <cwchar>
#include <mk_wcswidth/mk_wcwidth.h>
#include <gsl/span>
namespace terminal_editor {
#if !defined(USE_NATIVE_WCWIDTH)
/// Returns number of columns required to represent given character.
/// Returns 0 for zero width caracters.
/// Throws when non-printable character is passed as argument.
/// @param ucs UTF-32 code point.
inline int wcwidth(uint32_t ucs) {
auto width = mk::wcwidth(ucs);
ZASSERT(width >= 0) << "Non-printable character encountered: " << ucs;
return width;
}
#else
inline int wcwidth(uint32_t ucs) {
auto width = ::wcwidth(ucs);
ZASSERT(width >= 0) << "Non-printable character encountered: " << ucs;
return width;
}
#endif
/// Returns number of columns required to represent given string.
/// Returns 0 for zero width strings.
/// Throws when non-printable characters are encountered.
/// @param ucs UTF-32 code point.
inline int wcswidth(gsl::span<const uint32_t> text) {
return std::accumulate(text.begin(), text.end(), 0, [](int width, const uint32_t ucs) { return width + wcwidth(ucs); });
}
} // namespace terminal_editor
| {
"alphanum_fraction": 0.7002497918,
"avg_line_length": 25.5531914894,
"ext": "h",
"hexsha": "532f07c2990803f9e7ff4261028dc3030bf71b25",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-21T00:37:06.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-21T00:37:06.000Z",
"max_forks_repo_head_hexsha": "375ac936f09543bab9c01fcb5a2dc8de9af83a58",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zbyl/terminal-editor",
"max_forks_repo_path": "editorlib/zwcwidth.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "375ac936f09543bab9c01fcb5a2dc8de9af83a58",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zbyl/terminal-editor",
"max_issues_repo_path": "editorlib/zwcwidth.h",
"max_line_length": 124,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "375ac936f09543bab9c01fcb5a2dc8de9af83a58",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zbyl/terminal-editor",
"max_stars_repo_path": "editorlib/zwcwidth.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 303,
"size": 1201
} |
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "BaseWorker.h"
#include "MageSlam.h"
#include <arcana/scheduling/state_machine.h>
#include <gsl/gsl>
#include <memory>
namespace mage
{
struct MageContext;
struct MageSlamSettings;
struct FrameData;
class Fuser;
class Runtime
{
public:
Runtime(const MageSlamSettings& settings, MageContext& context, Fuser& fuser, mira::state_machine_driver& driver);
~Runtime();
void Run(gsl::span<const MAGESlam::CameraConfiguration> cameras);
void TrackMono(std::shared_ptr<FrameData> frame);
void TrackStereo(std::shared_ptr<FrameData> one, std::shared_ptr<FrameData> two);
void AddSample(const mage::SensorSample& sample);
private:
struct Impl;
const std::unique_ptr<Impl> m_impl;
};
}
| {
"alphanum_fraction": 0.6833144154,
"avg_line_length": 22.5897435897,
"ext": "h",
"hexsha": "7e7634aa1043baa465ad1372134de36384f3286d",
"lang": "C",
"max_forks_count": 16,
"max_forks_repo_forks_event_max_datetime": "2022-03-31T15:36:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-05-07T03:09:13.000Z",
"max_forks_repo_head_hexsha": "ba79a4e6315689c072c29749de18d70279a4c5e4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "syntheticmagus/mageslam",
"max_forks_repo_path": "Core/MAGESLAM/Source/Tasks/Runtime.h",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ba79a4e6315689c072c29749de18d70279a4c5e4",
"max_issues_repo_issues_event_max_datetime": "2020-10-08T07:43:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-06-01T00:34:01.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "syntheticmagus/mageslam",
"max_issues_repo_path": "Core/MAGESLAM/Source/Tasks/Runtime.h",
"max_line_length": 122,
"max_stars_count": 70,
"max_stars_repo_head_hexsha": "ba79a4e6315689c072c29749de18d70279a4c5e4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "syntheticmagus/mageslam",
"max_stars_repo_path": "Core/MAGESLAM/Source/Tasks/Runtime.h",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T01:04:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-07T03:09:09.000Z",
"num_tokens": 211,
"size": 881
} |
#pragma once
#include "Cesium3DTilesSelection/Library.h"
#include <glm/mat4x4.hpp>
#include <glm/vec2.hpp>
#include <gsl/span>
namespace CesiumGeometry {
struct Rectangle;
}
namespace CesiumGltf {
struct ImageCesium;
struct Model;
} // namespace CesiumGltf
namespace Cesium3DTilesSelection {
class Tile;
class RasterOverlayTile;
/**
* @brief When implemented for a rendering engine, allows renderer resources to
* be created and destroyed under the control of a {@link Tileset}.
*
* It is not supposed to be used directly by clients. It is implemented
* for specific rendering engines to provide an infrastructure for preparing the
* data of a {@link Tile} so that it can be used for rendering.
*
* Instances of this class are associated with a {@link Tileset}, in the
* {@link TilesetExternals} structure that can be obtained
* via {@link Tileset::getExternals}.
*/
class CESIUM3DTILESSELECTION_API IPrepareRendererResources {
public:
virtual ~IPrepareRendererResources() = default;
/**
* @brief Prepares renderer resources for the given tile.
*
* This method is invoked in the load thread, and it may not modify the tile.
*
* @param model The glTF model to prepare.
* @param transform The tile's transformation.
* @returns Arbitrary data representing the result of the load process. This
* data is passed to {@link prepareInMainThread} as the `pLoadThreadResult`
* parameter.
*/
virtual void* prepareInLoadThread(
const CesiumGltf::Model& model,
const glm::dmat4& transform) = 0;
/**
* @brief Further prepares renderer resources.
*
* This is called after {@link prepareInLoadThread}, and unlike that method,
* this one is called from the same thread that called
* {@link Tileset::updateView}.
*
* @param tile The tile to prepare.
* @param pLoadThreadResult The value returned from
* {@link prepareInLoadThread}.
* @returns Arbitrary data representing the result of the load process.
* Note that the value returned by {@link prepareInLoadThread} will _not_ be
* automatically preserved and passed to {@link free}. If you need to free
* that value, do it in this method before returning. If you need that value
* later, add it to the object returned from this method.
*/
virtual void* prepareInMainThread(Tile& tile, void* pLoadThreadResult) = 0;
/**
* @brief Frees previously-prepared renderer resources.
*
* This method is always called from the thread that called
* {@link Tileset::updateView} or deleted the tileset.
*
* @param tile The tile for which to free renderer resources.
* @param pLoadThreadResult The result returned by
* {@link prepareInLoadThread}. If {@link prepareInMainThread} has
* already been called, this parameter will be `nullptr`.
* @param pMainThreadResult The result returned by
* {@link prepareInMainThread}. If {@link prepareInMainThread} has
* not yet been called, this parameter will be `nullptr`.
*/
virtual void free(
Tile& tile,
void* pLoadThreadResult,
void* pMainThreadResult) noexcept = 0;
/**
* @brief Prepares a raster overlay tile.
*
* This method is invoked in the load thread, and it may not modify the tile.
*
* @param image The raster tile image to prepare.
* @returns Arbitrary data representing the result of the load process. This
* data is passed to {@link prepareRasterInMainThread} as the
* `pLoadThreadResult` parameter.
*/
virtual void*
prepareRasterInLoadThread(const CesiumGltf::ImageCesium& image) = 0;
/**
* @brief Further preprares a raster overlay tile.
*
* This is called after {@link prepareRasterInLoadThread}, and unlike that
* method, this one is called from the same thread that called
* {@link Tileset::updateView}.
*
* @param rasterTile The raster tile to prepare.
* @param pLoadThreadResult The value returned from
* {@link prepareInLoadThread}.
* @returns Arbitrary data representing the result of the load process. Note
* that the value returned by {@link prepareRasterInLoadThread} will _not_ be
* automatically preserved and passed to {@link free}. If you need to free
* that value, do it in this method before returning. If you need that value
* later, add it to the object returned from this method.
*/
virtual void* prepareRasterInMainThread(
const RasterOverlayTile& rasterTile,
void* pLoadThreadResult) = 0;
/**
* @brief Frees previously-prepared renderer resources for a raster tile.
*
* This method is always called from the thread that called
* {@link Tileset::updateView} or deleted the tileset.
*
* @param rasterTile The tile for which to free renderer resources.
* @param pLoadThreadResult The result returned by
* {@link prepareRasterInLoadThread}. If {@link prepareRasterInMainThread}
* has already been called, this parameter will be `nullptr`.
* @param pMainThreadResult The result returned by
* {@link prepareRasterInMainThread}. If {@link prepareRasterInMainThread}
* has not yet been called, this parameter will be `nullptr`.
*/
virtual void freeRaster(
const RasterOverlayTile& rasterTile,
void* pLoadThreadResult,
void* pMainThreadResult) noexcept = 0;
/**
* @brief Attaches a raster overlay tile to a geometry tile.
*
* @param tile The geometry tile.
* @param overlayTextureCoordinateID The ID of the overlay texture coordinate
* set to use.
* @param rasterTile The raster overlay tile to add. The raster tile will have
* been previously prepared with a call to {@link prepareRasterInLoadThread}
* followed by {@link prepareRasterInMainThread}.
* @param pMainThreadRendererResources The renderer resources for this raster
* tile, as created and returned by {@link prepareRasterInMainThread}.
* @param textureCoordinateRectangle Defines the range of texture coordinates
* in which this raster tile should be applied, in the order west, south, east
* north. Each coordinate is in the range 0.0 (southwest corner) to 1.0
* (northeast corner).
* @param translation The translation to apply to the texture coordinates
* identified by `overlayTextureCoordinateID`. The texture coordinates to use
* to sample the raster image are computed as `overlayTextureCoordinates *
* scale + translation`.
* @param scale The scale to apply to the texture coordinates identified by
* `overlayTextureCoordinateID`. The texture coordinates to use to sample the
* raster image are computed as `overlayTextureCoordinates * scale +
* translation`.
*/
virtual void attachRasterInMainThread(
const Tile& tile,
uint32_t overlayTextureCoordinateID,
const RasterOverlayTile& rasterTile,
void* pMainThreadRendererResources,
const CesiumGeometry::Rectangle& textureCoordinateRectangle,
const glm::dvec2& translation,
const glm::dvec2& scale) = 0;
/**
* @brief Detaches a raster overlay tile from a geometry tile.
*
* @param tile The geometry tile.
* @param overlayTextureCoordinateID The ID of the overlay texture coordinate
* set to which the raster tile was previously attached.
* @param rasterTile The raster overlay tile to remove.
* @param pMainThreadRendererResources The renderer resources for this raster
* tile, as created and returned by {@link prepareRasterInMainThread}.
* @param textureCoordinateRectangle Defines the range of texture coordinates
* in which this raster tile should be applied, in the order west, south, east
* north. Each coordinate is in the range 0.0 (southwest corner) to 1.0
* (northeast corner).
*/
virtual void detachRasterInMainThread(
const Tile& tile,
uint32_t overlayTextureCoordinateID,
const RasterOverlayTile& rasterTile,
void* pMainThreadRendererResources,
const CesiumGeometry::Rectangle& textureCoordinateRectangle) noexcept = 0;
};
} // namespace Cesium3DTilesSelection
| {
"alphanum_fraction": 0.729702723,
"avg_line_length": 40.4343434343,
"ext": "h",
"hexsha": "145ee77148f9d23ce76178515628db10b39778d9",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5265a65053542fe02928c272762c6b89fa2b29bb",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "zrkcode/cesium-native",
"max_forks_repo_path": "Cesium3DTilesSelection/include/Cesium3DTilesSelection/IPrepareRendererResources.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5265a65053542fe02928c272762c6b89fa2b29bb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "zrkcode/cesium-native",
"max_issues_repo_path": "Cesium3DTilesSelection/include/Cesium3DTilesSelection/IPrepareRendererResources.h",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5265a65053542fe02928c272762c6b89fa2b29bb",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "zrkcode/cesium-native",
"max_stars_repo_path": "Cesium3DTilesSelection/include/Cesium3DTilesSelection/IPrepareRendererResources.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1892,
"size": 8006
} |
/* -*- c++ -*- */
/*
* Copyright 2015 Free Software Foundation, Inc.
*
* This 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 3, or (at your
* option) any later version.
*
* This software 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 software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef INCLUDED_ldpc_G_matrix_impl_H
#define INCLUDED_ldpc_G_matrix_impl_H
#include <gsl/gsl_randist.h>
#include <gsl/gsl_permutation.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_blas.h>
#include "fec_mtrx_impl.h"
#include <gnuradio/fec/ldpc_G_matrix.h>
#include <gnuradio/fec/ldpc_H_matrix.h>
#include <gnuradio/logger.h>
namespace gr {
namespace fec {
namespace code {
/*!
* \brief Class for storing H or G matrix
* \ingroup error_coding_blk
*
* \details
* This class stores a GSL matrix variable, specifically
* either a:
*
* 1) Generator matrix, G, in the standard format G = [I P],
* where I is an identity matrix and P is the parity
* submatrix.
*
* or
*
* 2) Parity matrix, H, in the standard format H = [P' I],
* where P' is the transpose of the parity submatrix and I
* is an identity matrix.
*
* This variable can used by the ldpc_gen_mtrx_encoder and
* ldpc_bit_flip_decoder classes.
*/
class ldpc_G_matrix_impl
: public fec_mtrx_impl, public ldpc_G_matrix
{
private:
// GSL matrix structure for transpose of G
gsl_matrix *d_G_transp_ptr;
gsl_matrix *d_H_obj;
//! Get the generator matrix (used during encoding)
const gsl_matrix *G_transpose() const;
gr::logger_ptr d_logger;
gr::logger_ptr d_debug_logger;
public:
ldpc_G_matrix_impl(const std::string filename);
void encode(unsigned char *outbuffer,
const unsigned char *inbuffer) const;
void decode(unsigned char *outbuffer,
const float *inbuffer,
unsigned int frame_size,
unsigned int max_iterations) const;
unsigned int n() const { return fec_mtrx_impl::n(); }
unsigned int k() const { return fec_mtrx_impl::k(); }
gsl_matrix* generate_H();
gr::fec::code::fec_mtrx_sptr get_base_sptr();
/*!
* \brief Destructor
* \details
* Calls the gsl_matrix_free function to free memory.
*/
virtual ~ldpc_G_matrix_impl();
};
}
}
}
#endif /* INCLUDED_ldpc_G_matrix_impl_H */
| {
"alphanum_fraction": 0.6368642695,
"avg_line_length": 29.4,
"ext": "h",
"hexsha": "5c2c44fef15458394861268b30a91485853557a0",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "64c149520ac6a7d44179c3f4a38f38add45dd5dc",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "v1259397/cosmic-gnuradio",
"max_forks_repo_path": "gnuradio-3.7.13.4/gr-fec/lib/ldpc_G_matrix_impl.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "64c149520ac6a7d44179c3f4a38f38add45dd5dc",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "v1259397/cosmic-gnuradio",
"max_issues_repo_path": "gnuradio-3.7.13.4/gr-fec/lib/ldpc_G_matrix_impl.h",
"max_line_length": 68,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "64c149520ac6a7d44179c3f4a38f38add45dd5dc",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "v1259397/cosmic-gnuradio",
"max_stars_repo_path": "gnuradio-3.7.13.4/gr-fec/lib/ldpc_G_matrix_impl.h",
"max_stars_repo_stars_event_max_datetime": "2021-03-09T07:32:37.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-03-09T07:32:37.000Z",
"num_tokens": 735,
"size": 3087
} |
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <MaxSLiCInterface.h>
#include "Maxfiles.h"
#include "dgemm.h"
#define TILE_SIZE DGEMM_tileSize
#define TILE_SIZE_2D (TILE_SIZE * TILE_SIZE)
#define FREQUENCY DGEMM_frequency
static size_t sizeInTiles(size_t n) {
return (n + TILE_SIZE - 1) / TILE_SIZE;
}
#ifdef USE_BLAS
#include <cblas.h>
#endif
void dgemm_model(
const char* trans_a, const char* trans_b, size_t m, size_t n, size_t k, double alpha,
const double* A, size_t lda, const double* B, size_t ldb, double beta, double* C, size_t ldc)
{
// TODO support transform
#ifdef USE_BLAS
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);
#else
for (size_t mm = 0; mm < m; ++mm) {
for (size_t nn = 0; nn < n; ++nn) {
C[mm*ldc+nn] *= beta;
for (size_t kk = 0; kk < k; ++kk) {
C[mm*ldc+nn] += alpha * A[mm*lda+kk] * B[kk*ldb+nn];
}
}
}
#endif
}
static struct timespec diff(struct timespec start, struct timespec finish) {
struct timespec diff;
if ((finish.tv_nsec < start.tv_nsec)) {
diff.tv_sec = finish.tv_sec - start.tv_sec - 1;
diff.tv_nsec = finish.tv_nsec - start.tv_nsec + 1000000000;
} else {
diff.tv_sec = finish.tv_sec - start.tv_sec;
diff.tv_nsec = finish.tv_nsec - start.tv_nsec;
}
return diff;
}
static int check_result(int m, int n, const double* expected, const double* actual) {
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
int idx = i*n + j;
if (expected[idx] != actual[idx]) {
return 1;
}
}
}
return 0;
}
int main(int argc, char** argv) {
unsigned seed = time(NULL);
printf("Random seed: %u\n", seed);
srand(seed);
size_t m;
size_t n;
size_t k;
if (argc == 1) {
m = (random() % (5 * TILE_SIZE)) + TILE_SIZE;
n = (random() % (5 * TILE_SIZE)) + TILE_SIZE;
k = (random() % (5 * TILE_SIZE)) + TILE_SIZE;
} else if (argc == 2) {
m = n = k = atoi(argv[1]);
} else {
printf("Usage: %s [size]\n", argv[0]);
exit(1);
}
double* A = calloc(m * k, sizeof(double));
double* B = calloc(k * n, sizeof(double));
double* Csw = calloc(m * n, sizeof(double));
double* Chw = calloc(m * n, sizeof(double));
printf("Matrix dimensions: m = %lu, n = %lu, k = %lu\n", m, n, k);
dgemm_init(m, n, k);
size_t mTiles = sizeInTiles(m);
size_t nTiles = sizeInTiles(n);
size_t kTiles = sizeInTiles(k);
printf("DFE tile size: %d\n", TILE_SIZE);
printf("DFE compute dimensions: m = %zu, n = %zu, k = %zu\n",
mTiles * TILE_SIZE, nTiles * TILE_SIZE, kTiles * TILE_SIZE);
double cpuPoints = ((double) m) * n * k;
double dfePoints = ((double) mTiles) * nTiles * kTiles * TILE_SIZE_2D;
printf("DFE compute efficiency: %f\n", cpuPoints / (dfePoints * TILE_SIZE));
printf("DFE frequency: %d MHz\n", FREQUENCY);
// add one tile to account for stream offset TODO measure pipeline depth properly?
printf("DFE predicted compute time: %f s\n", (dfePoints + TILE_SIZE_2D) / (((double) FREQUENCY) * 1e6));
for (size_t i = 0; i < m*k; ++i) {
A[i] = random() % 100;
}
for (size_t i = 0; i < k*n; ++i) {
B[i] = random() % 100;
}
for (size_t i = 0; i < m*n; ++i) {
Csw[i] = random() % 100;
Chw[i] = Csw[i];
}
// TODO random
double alpha = 1;
double beta = 0;
struct timespec start;
struct timespec finish;
for (int xx = 0; xx < 5; ++xx) {
printf("Repeat %d\n", xx);
printf("Running HW... "); fflush(stdout);
clock_gettime(CLOCK_REALTIME, &start);
dgemm("n", "n", m, n, k, alpha, A, k, B, n, beta, Chw, n);
clock_gettime(CLOCK_REALTIME, &finish);
struct timespec hw_time = diff(start, finish);
printf("took: %ld.%09ld s\n", hw_time.tv_sec, hw_time.tv_nsec);
}
printf("Running SW... "); fflush(stdout);
clock_gettime(CLOCK_REALTIME, &start);
dgemm_model("n", "n", m, n, k, alpha, A, k, B, n, beta, Csw, n);
clock_gettime(CLOCK_REALTIME, &finish);
struct timespec sw_time = diff(start, finish);
printf("took: %ld.%09ld s\n", sw_time.tv_sec, sw_time.tv_nsec);
printf("Comparing results... ");
int failed = check_result(m, n, Csw, Chw);
printf("%s\n", failed ? "WRONG" : "CORRECT");
printf("Done.\n");
return failed;
}
| {
"alphanum_fraction": 0.6267181095,
"avg_line_length": 26.5833333333,
"ext": "c",
"hexsha": "d963cd182f293b605f12ffb9444aa5c60fb359a4",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-11-05T10:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-05T10:49:17.000Z",
"max_forks_repo_head_hexsha": "565a623911d8466999cf2aa6a04b898e521c68cf",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "MaxelerTechnologies/Dense-Matrix-Multiplication",
"max_forks_repo_path": "APP/CPUCode/Example/src/dgemm_example.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "565a623911d8466999cf2aa6a04b898e521c68cf",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "MaxelerTechnologies/Dense-Matrix-Multiplication",
"max_issues_repo_path": "APP/CPUCode/Example/src/dgemm_example.c",
"max_line_length": 105,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "de43acae7c88cefca126f65e9fdc49609fa372bc",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "nilsv/Dense-Matrix-Multiplication",
"max_stars_repo_path": "APP/CPUCode/Example/src/dgemm_example.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-14T18:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-28T19:25:54.000Z",
"num_tokens": 1386,
"size": 4147
} |
/**
*
* @file core_ztrmdm.c
*
* PLASMA core_blas kernel
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.4.5
* @author Dulceneia Becker
* @date 2011-1-18
**/
/*
* @precisions normal z -> c d s
*/
#include <lapacke.h>
#include "dplasma_cores.h"
#include "dplasma_zcores.h"
#if defined(PARSEC_HAVE_STRING_H)
#include <string.h>
#endif /* defined(PARSEC_HAVE_STRING_H) */
#if defined(PARSEC_HAVE_STDARG_H)
#include <stdarg.h>
#endif /* defined(PARSEC_HAVE_STDARG_H) */
#include <stdio.h>
#ifdef PARSEC_HAVE_LIMITS_H
#include <limits.h>
#endif
#include <cblas.h>
#include <core_blas.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
int CORE_ztrmdm(int uplo, int N, PLASMA_Complex64_t *A, int LDA);
/***************************************************************************//**
*
* @ingroup CORE_PLASMA_Complex64_t
*
* CORE_ztrmdm scales the strictly upper or strictly lower triangular part of a
* square matrix by the inverse of a diagonal matrix, ie performs either
*
* A := L / D or A := U / D (only for triangular part above or below diagonal)
*
* where:
*
* L is a strictly lower triangular matrix stored as the strictly lower triangle in A
* U is a strictly upper triangular matrix stored as the strictly upper triangle in A
* D is a diagonal matrix stored as the diagonal in A
*
* The diagonal elements of A are not changed.
*
*******************************************************************************
*
* @param[in] uplo
* INTEGER
* @arg PlasmaLower: Lower triangle of A is stored and scaled.
* @arg PlasmaUpper: Upper triangle of A is stored and scaled.
*
* @param[in] N
* INTEGER
* The number of rows and columns of A. N >= 0.
*
* @param[in,out] A
* PLASMA_Complex64_t array, dimension (LDA,N)
*
* On entry, the triangular matrix A. If uplo = 'U', the leading
* N-by-N upper triangular part of A contains the upper
* triangular part of the matrix A, and the strictly lower
* triangular part of A is not referenced. If uplo = 'L', the
* leading N-by-N lower triangular part of A contains the lower
* triangular part of the matrix A, and the strictly upper
* triangular part of A is not referenced.
*
* On exit, the strictly lower or upper triangular part of A
* scaled by the diagonal elements of A.
*
* @param[in] LDA
* INTEGER
* The leading dimension of the array A. LDA >= max(1,N).
*
*******************************************************************************
*
* @return
* \retval PLASMA_SUCCESS successful exit
* \retval <0 if -i, the i-th argument had an illegal value
*
******************************************************************************/
#if defined(PLASMA_PARSEC_HAVE_WEAK)
#pragma weak CORE_ztrmdm = PCORE_ztrmdm
#define CORE_ztrmdm PCORE_ztrmdm
#endif
int CORE_ztrmdm(int uplo, int N, PLASMA_Complex64_t *A, int LDA)
{
static PLASMA_Complex64_t zone = 1.0;
PLASMA_Complex64_t alpha;
int j;
/* Check input arguments */
if (uplo != PlasmaUpper && uplo != PlasmaLower) {
coreblas_error(1, "Illegal value of UPLO");
return -1;
}
if (N < 0) {
coreblas_error(2, "Illegal value of N");
return -2;
}
if (LDA < max(1, N)) {
coreblas_error(1, "Illegal value of LDA");
return -4;
}
/* Quick return */
if (max(N, 0) == 0)
return PLASMA_SUCCESS;
/**/
if (uplo==PlasmaLower) {
for (j=0; j<(N-1); j++) {
alpha = zone / A[LDA*j+j];
cblas_zscal(N-j-1, CBLAS_SADDR(alpha), &A[LDA*j+j+1], 1);
}
} else if (uplo==PlasmaUpper) {
for (j=1; j<N; j++) {
alpha = zone / A[LDA*j+j];
cblas_zscal(j, CBLAS_SADDR(alpha), &A[LDA*j], 1);
}
}
return PLASMA_SUCCESS;
}
| {
"alphanum_fraction": 0.5657830142,
"avg_line_length": 29.1,
"ext": "c",
"hexsha": "74cbbde82826980aeab592321d2016e907640900",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "73af5b9ffe65cdb06b58c0cb34029ee6265d2bf8",
"max_forks_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_forks_repo_name": "NLAFET/ABFT",
"max_forks_repo_path": "dplasma/cores/core_ztrmdm.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "73af5b9ffe65cdb06b58c0cb34029ee6265d2bf8",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_issues_repo_name": "NLAFET/ABFT",
"max_issues_repo_path": "dplasma/cores/core_ztrmdm.c",
"max_line_length": 88,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "73af5b9ffe65cdb06b58c0cb34029ee6265d2bf8",
"max_stars_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_stars_repo_name": "NLAFET/ABFT",
"max_stars_repo_path": "dplasma/cores/core_ztrmdm.c",
"max_stars_repo_stars_event_max_datetime": "2019-08-13T10:13:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-13T10:13:00.000Z",
"num_tokens": 1103,
"size": 4074
} |
/**
*
* @file core_zlaset2.c
*
* PLASMA core_blas kernel
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Hatem Ltaief
* @date 2010-11-15
* @precisions normal z -> c d s
*
**/
#include <lapacke.h>
#include "common.h"
/***************************************************************************//**
*
* @ingroup CORE_PLASMA_Complex64_t
*
* CORE_zlaset2 - Sets the elements of the matrix A to alpha.
* Not LAPACK compliant! Read below.
*
*******************************************************************************
*
* @param[in] uplo
* Specifies which elements of the matrix are to be set
* = PlasmaUpper: STRICT Upper part of A is set to alpha;
* = PlasmaLower: STRICT Lower part of A is set to alpha;
* = PlasmaUpperLower: ALL elements of A are set to alpha.
* Not LAPACK Compliant.
*
* @param[in] M
* The number of rows of the matrix A. M >= 0.
*
* @param[in] N
* The number of columns of the matrix A. N >= 0.
*
* @param[in] alpha
* The constant to which the elements are to be set.
*
* @param[in,out] A
* On entry, the M-by-N tile A.
* On exit, A has been set to alpha accordingly.
*
* @param[in] LDA
* The leading dimension of the array A. LDA >= max(1,M).
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_zlaset2 = PCORE_zlaset2
#define CORE_zlaset2 PCORE_zlaset2
#endif
void CORE_zlaset2(PLASMA_enum uplo, int M, int N,
PLASMA_Complex64_t alpha, PLASMA_Complex64_t *A, int LDA)
{
if (uplo == PlasmaUpper) {
LAPACKE_zlaset_work(
LAPACK_COL_MAJOR,
lapack_const(uplo),
M, N-1, alpha, alpha, A+LDA, LDA);
}
else if (uplo == PlasmaLower) {
LAPACKE_zlaset_work(
LAPACK_COL_MAJOR,
lapack_const(uplo),
M-1, N, alpha, alpha, A+1, LDA);
}
else {
LAPACKE_zlaset_work(
LAPACK_COL_MAJOR,
lapack_const(uplo),
M, N, alpha, alpha, A, LDA);
}
}
| {
"alphanum_fraction": 0.551199262,
"avg_line_length": 28.1558441558,
"ext": "c",
"hexsha": "535f4d80eb3dfdf1b06ad92f0ed001d426880fa0",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zhuangsc/Plasma-ompss1",
"max_forks_repo_path": "core_blas/core_zlaset2.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zhuangsc/Plasma-ompss1",
"max_issues_repo_path": "core_blas/core_zlaset2.c",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zhuangsc/Plasma-ompss1",
"max_stars_repo_path": "core_blas/core_zlaset2.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 603,
"size": 2168
} |
#include <gsl/gsl_test.h>
#include <gsl/gsl_ieee_utils.h>
#include <gsl/gsl_math.h>
#include "gsl_cblas.h"
#include "tests.h"
void
test_trmm (void) {
const double flteps = 1e-4, dbleps = 1e-6;
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { 0.565f, 0.967f, -0.969f, 0.184f };
int lda = 2;
float B[] = { 0.842f, -0.918f, -0.748f, -0.859f, -0.463f, 0.292f };
int ldb = 3;
float B_expected[] = { -0.354923f, -0.966391f, -0.140256f, -0.158056f, -0.085192f, 0.053728f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1670)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.748f, 0.548f, 0.245f, 0.761f };
int lda = 2;
float B[] = { 0.349f, -0.552f, -0.682f, -0.71f, 0.475f, -0.59f };
int ldb = 3;
float B_expected[] = { -0.04008f, -0.2917f, -1.00532f, -0.71f, 0.475f, -0.59f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1671)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { 0.788f, 0.617f, -0.998f, -0.97f };
int lda = 2;
float B[] = { -0.4f, 0.773f, 0.074f, -0.388f, 0.825f, -0.608f };
int ldb = 3;
float B_expected[] = { -0.3152f, 0.609124f, 0.058312f, 0.77556f, -1.5717f, 0.515908f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1672)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { 0.01f, 0.387f, -0.953f, -0.374f };
int lda = 2;
float B[] = { 0.364f, 0.09f, 0.588f, -0.263f, 0.584f, 0.463f };
int ldb = 3;
float B_expected[] = { 0.364f, 0.09f, 0.588f, -0.609892f, 0.49823f, -0.097364f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1673)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.586f, -0.426f, 0.765f, -0.239f };
int lda = 2;
float B[] = { -0.673f, -0.724f, 0.217f, -0.672f, -0.378f, -0.005f };
int ldb = 2;
float B_expected[] = { -0.159482f, 0.173036f, -0.641242f, 0.160608f, 0.217683f, 0.001195f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1674)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.668f, 0.962f, 0.515f, 0.292f };
int lda = 2;
float B[] = { -0.145f, -0.337f, 0.718f, -0.866f, -0.454f, -0.439f };
int ldb = 2;
float B_expected[] = { -0.318555f, -0.337f, 0.27201f, -0.866f, -0.680085f, -0.439f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1675)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.125f, -0.676f, 0.181f, 0.741f };
int lda = 2;
float B[] = { 0.354f, -0.366f, 0.455f, 0.134f, -0.564f, -0.303f };
int ldb = 2;
float B_expected[] = { -0.04425f, -0.51051f, -0.056875f, -0.208286f, 0.0705f, 0.156741f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1676)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.162f, 0.542f, -0.839f, -0.935f };
int lda = 2;
float B[] = { 0.216f, 0.766f, -0.228f, -0.097f, 0.205f, 0.875f };
int ldb = 2;
float B_expected[] = { 0.216f, 0.883072f, -0.228f, -0.220576f, 0.205f, 0.98611f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1677)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.353f, -0.854f, -0.502f, 0.591f, -0.934f, -0.729f, 0.063f, 0.352f, 0.126f };
int lda = 3;
float B[] = { 0.2f, -0.626f, -0.694f, -0.889f, -0.251f, -0.42f };
int ldb = 3;
float B_expected[] = { -0.0706f, 0.413884f, 0.26851f, 0.313817f, 0.99364f, 0.576337f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1678)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.864f, -0.046f, -0.755f, 0.12f, 0.525f, 0.917f, 0.571f, -0.098f, -0.226f };
int lda = 3;
float B[] = { -0.905f, -0.296f, -0.927f, -0.813f, 0.624f, -0.366f };
int ldb = 3;
float B_expected[] = { -0.905f, -0.25437f, -0.515157f, -0.813f, 0.661398f, 0.820023f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1679)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.69f, -0.927f, -0.281f, -0.918f, -0.527f, -0.652f, -0.393f, -0.954f, 0.651f };
int lda = 3;
float B[] = { -0.587f, 0.788f, -0.629f, -0.444f, 0.515f, 0.081f };
int ldb = 3;
float B_expected[] = { -0.071157f, 0.18479f, -0.409479f, -0.198243f, -0.348679f, 0.052731f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1680)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.082f, -0.077f, 0.811f, 0.852f, 0.224f, 0.443f, -0.509f, 0.171f, 0.986f };
int lda = 3;
float B[] = { -0.982f, 0.388f, -0.493f, -0.497f, -0.605f, 0.433f };
int ldb = 3;
float B_expected[] = { -0.400487f, 0.303697f, -0.493f, -1.23286f, -0.530957f, 0.433f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1681)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { 0.97f, -0.666f, 0.066f, -0.176f, 0.402f, 0.286f, -0.703f, 0.962f, 0.912f };
int lda = 3;
float B[] = { -0.644f, -0.97f, 0.814f, -0.777f, 0.812f, 0.254f };
int ldb = 2;
float B_expected[] = { -0.62468f, -0.9409f, 0.440572f, -0.141634f, 1.97634f, 0.166084f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1682)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { 0.714f, 0.468f, 0.859f, -0.547f, 0.076f, 0.542f, 0.512f, -0.987f, -0.167f };
int lda = 3;
float B[] = { -0.238f, -0.336f, 0.402f, 0.945f, -0.242f, -0.062f };
int ldb = 2;
float B_expected[] = { -0.238f, -0.336f, 0.532186f, 1.12879f, -0.76063f, -1.16675f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1683)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.723f, 0.041f, 0.333f, -0.682f, 0.193f, 0.581f, 0.963f, -0.757f, 0.396f };
int lda = 3;
float B[] = { 0.047f, -0.701f, -0.25f, -0.779f, 0.435f, 0.612f };
int ldb = 2;
float B_expected[] = { 0.100624f, 0.67868f, 0.204485f, 0.205225f, 0.17226f, 0.242352f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1684)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 1.0f;
float A[] = { -0.13f, 0.511f, -0.544f, 0.938f, -0.126f, -0.873f, 0.118f, -0.75f, 0.674f };
int lda = 3;
float B[] = { -0.927f, -0.558f, -0.289f, -0.66f, 0.83f, 0.363f };
int ldb = 2;
float B_expected[] = { -1.5262f, -1.09273f, -1.01359f, -0.976899f, 0.83f, 0.363f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1685)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.625f, -0.123f, -0.48f, -0.088f };
int lda = 2;
float B[] = { 0.376f, -0.46f, -0.813f, 0.419f, 0.792f, 0.226f };
int ldb = 3;
float B_expected[] = { -0.0235f, 0.02875f, 0.0508125f, -0.008312f, -0.0013116f, 0.0080111f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1686)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.038f, -0.105f, -0.946f, 0.474f };
int lda = 2;
float B[] = { -0.757f, 0.974f, -0.045f, -0.809f, 0.654f, 0.611f };
int ldb = 3;
float B_expected[] = { -0.0757f, 0.0974f, -0.0045f, -0.0729515f, 0.055173f, 0.0615725f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1687)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.328f, 0.713f, 0.781f, 0.084f };
int lda = 2;
float B[] = { -0.097f, 0.442f, -0.563f, 0.065f, -0.18f, 0.63f };
int ldb = 3;
float B_expected[] = { 0.0082581f, -0.0285556f, 0.0676694f, 5.46e-04f, -0.001512f, 0.005292f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1688)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { 0.261f, -0.659f, -0.536f, 0.694f };
int lda = 2;
float B[] = { -0.498f, 0.692f, 0.125f, 0.706f, -0.118f, -0.907f };
int ldb = 3;
float B_expected[] = { -0.0876416f, 0.0755248f, 0.0611152f, 0.0706f, -0.0118f, -0.0907f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1689)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.669f, 0.416f, 0.761f, -0.359f };
int lda = 2;
float B[] = { -0.305f, -0.675f, -0.442f, 0.566f, 0.064f, 0.962f };
int ldb = 2;
float B_expected[] = { 0.0204045f, 0.001022f, 0.0295698f, -0.0539556f, -0.0042816f, -0.0296654f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1690)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { 0.565f, 0.386f, 0.643f, -0.028f };
int lda = 2;
float B[] = { 0.863f, -0.241f, 0.766f, 0.656f, -0.977f, 0.274f };
int ldb = 2;
float B_expected[] = { 0.0863f, 0.0313909f, 0.0766f, 0.114854f, -0.0977f, -0.0354211f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1691)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { 0.116f, 0.534f, 0.043f, 0.73f };
int lda = 2;
float B[] = { -0.758f, -0.63f, -0.043f, 0.666f, -0.088f, 0.382f };
int ldb = 2;
float B_expected[] = { -0.0424348f, -0.04599f, 0.0350656f, 0.048618f, 0.019378f, 0.027886f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1692)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { 0.48f, -0.63f, -0.786f, -0.437f };
int lda = 2;
float B[] = { 0.945f, 0.528f, -0.855f, -0.587f, 0.062f, 0.372f };
int ldb = 2;
float B_expected[] = { 0.061236f, 0.0528f, -0.048519f, -0.0587f, -0.017236f, 0.0372f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1693)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.822f, -0.068f, 0.119f, -0.244f, -0.05f, 0.685f, 0.752f, -0.059f, -0.935f };
int lda = 3;
float B[] = { -0.431f, -0.753f, -0.319f, 0.164f, 0.979f, 0.885f };
int ldb = 3;
float B_expected[] = { 0.0367525f, -0.0180865f, 0.0298265f, -0.0096065f, 0.0557275f, -0.0827475f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1694)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { 0.97f, -0.408f, 0.174f, -0.308f, 0.997f, -0.484f, 0.322f, -0.183f, 0.849f };
int lda = 3;
float B[] = { -0.571f, 0.696f, -0.256f, -0.178f, 0.098f, 0.004f };
int ldb = 3;
float B_expected[] = { -0.0899512f, 0.0819904f, -0.0256f, -0.0217288f, 0.0096064f, 4.0e-04f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1695)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.831f, 0.73f, 0.407f, 0.721f, 0.086f, -0.294f, 0.941f, -0.656f, -0.066f };
int lda = 3;
float B[] = { -0.051f, -0.343f, -0.98f, 0.722f, -0.372f, 0.466f };
int ldb = 3;
float B_expected[] = { 0.0042381f, -0.0066269f, 0.0241697f, -0.0599982f, 0.048857f, 0.0892678f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1696)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { 0.472f, 0.137f, -0.341f, 0.386f, -0.578f, 0.863f, -0.415f, -0.547f, -0.023f };
int lda = 3;
float B[] = { 0.582f, 0.141f, -0.306f, -0.047f, -0.162f, -0.784f };
int ldb = 3;
float B_expected[] = { 0.0582f, 0.0365652f, -0.0624657f, -0.0047f, -0.0180142f, -0.0675881f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1697)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.775f, 0.762f, -0.038f, -0.8f, 0.626f, -0.701f, 0.639f, 0.239f, 0.34f };
int lda = 3;
float B[] = { 0.42f, 0.917f, 0.485f, 0.844f, -0.832f, 0.179f };
int ldb = 2;
float B_expected[] = { -0.124515f, -0.127149f, 0.0104762f, 0.0571125f, -0.028288f, 0.006086f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1698)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.675f, 0.283f, 0.785f, -0.0f, -0.592f, -0.661f, 0.149f, -0.129f, 0.149f };
int lda = 3;
float B[] = { 0.964f, -0.575f, -0.215f, 0.953f, 0.527f, -0.418f };
int ldb = 2;
float B_expected[] = { 0.104252f, -0.0637282f, -0.0282983f, 0.100692f, 0.0527f, -0.0418f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1699)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.225f, -0.943f, 0.839f, 0.759f, 0.752f, 0.807f, 0.288f, -0.276f, 0.434f };
int lda = 3;
float B[] = { -0.234f, 0.275f, 0.658f, -0.423f, -0.807f, -0.683f };
int ldb = 2;
float B_expected[] = { 0.005265f, -0.0061875f, 0.0715478f, -0.0577421f, -0.0015558f, -0.0407058f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1700)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha = 0.1f;
float A[] = { -0.043f, -0.983f, 0.479f, -0.136f, 0.048f, 0.745f, -0.408f, -0.731f, -0.953f };
int lda = 3;
float B[] = { 0.917f, 0.682f, -0.32f, 0.557f, -0.302f, 0.989f };
int ldb = 2;
float B_expected[] = { 0.0917f, 0.0682f, -0.122141f, -0.0113406f, -0.0101157f, 0.173064f };
cblas_strmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], flteps, "strmm(case 1701)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.561, -0.114, -0.148, 0.488 };
int lda = 2;
double B[] = { 0.684, 0.38, 0.419, -0.361, 0.378, -0.423 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1702)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.378, 0.607, 0.41, 0.418 };
int lda = 2;
double B[] = { 0.146, -0.688, -0.953, -0.983, 0.237, 0.128 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1703)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.31, 0.277, -0.587, 0.885 };
int lda = 2;
double B[] = { -0.221, -0.831, -0.319, -0.547, -0.577, 0.295 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1704)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.577, 0.861, -0.439, -0.916 };
int lda = 2;
double B[] = { -0.933, -0.582, 0.528, 0.268, -0.804, 0.62 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1705)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.824, -0.119, -0.399, -0.653 };
int lda = 2;
double B[] = { 0.452, -0.168, 0.256, 0.554, 0.342, 0.318 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1706)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.299, 0.837, -0.03, 0.552 };
int lda = 2;
double B[] = { -0.83, -0.82, -0.362, -0.252, -0.062, -0.942 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1707)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.545, -0.107, 0.096, 0.183 };
int lda = 2;
double B[] = { -0.43, 0.841, 0.035, 0.7, 0.637, 0.095 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1708)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.626, 0.123, -0.959, 0.971 };
int lda = 2;
double B[] = { 0.185, -0.218, -0.074, 0.49, 0.802, -0.454 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1709)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.131, 0.048, 0.148, 0.834, -0.98, -0.009, -0.727, 0.241, 0.276 };
int lda = 3;
double B[] = { 0.75, -0.664, -0.136, -0.793, -0.742, 0.126 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1710)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.431, -0.387, 0.427, 0.495, 0.282, 0.158, -0.335, 0.535, -0.978 };
int lda = 3;
double B[] = { 0.518, -0.489, 0.899, -0.375, 0.376, -0.831 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1711)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.669, -0.976, -0.2, 0.661, -0.975, -0.965, -0.861, -0.779, -0.73 };
int lda = 3;
double B[] = { 0.31, 0.023, -0.853, 0.632, -0.174, 0.608 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1712)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.153, -0.408, -0.127, -0.634, -0.384, -0.815, 0.051, -0.096, 0.476 };
int lda = 3;
double B[] = { 0.343, -0.665, -0.348, 0.748, 0.893, 0.91 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1713)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.918, -0.19, 0.829, 0.942, 0.885, 0.087, 0.321, 0.67, -0.475 };
int lda = 3;
double B[] = { 0.377, 0.931, 0.291, -0.603, -0.617, 0.402 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1714)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.598, -0.232, -0.64, 0.595, 0.642, -0.921, -0.679, -0.846, -0.921 };
int lda = 3;
double B[] = { 0.032, -0.036, -0.278, -0.83, 0.922, -0.701 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1715)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.341, -0.858, -0.559, 0.499, -0.114, 0.57, 0.847, -0.612, 0.593 };
int lda = 3;
double B[] = { 0.672, 0.292, 0.752, 0.842, 0.625, 0.967 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1716)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.958, 0.823, -0.181, 0.141, 0.932, 0.097, -0.636, 0.844, 0.205 };
int lda = 3;
double B[] = { 0.113, -0.658, 0.703, -0.023, -0.384, 0.439 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1717)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.675, -0.468, -0.564, 0.71 };
int lda = 2;
double B[] = { -0.401, -0.823, 0.342, -0.384, 0.344, 0.18 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1718)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.932, -0.388, 0.432, -0.167 };
int lda = 2;
double B[] = { -0.624, 0.023, 0.065, 0.678, 0.044, -0.472 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1719)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.738, 0.649, -0.171, -0.462 };
int lda = 2;
double B[] = { -0.277, -0.519, -0.501, -0.024, -0.767, -0.591 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1720)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.17, -0.184, -0.243, 0.907 };
int lda = 2;
double B[] = { 0.593, 0.131, -0.317, -0.254, -0.948, 0.002 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1721)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.06, -0.838, -0.455, -0.715 };
int lda = 2;
double B[] = { -0.423, 0.665, -0.023, -0.872, -0.313, -0.698 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1722)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.506, 0.792, 0.338, -0.155 };
int lda = 2;
double B[] = { -0.257, -0.19, 0.201, 0.685, 0.663, 0.302 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1723)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.739, -0.996, 0.182, 0.626 };
int lda = 2;
double B[] = { 0.009, 0.485, -0.633, -0.08, -0.579, 0.223 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1724)");
}
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.777, 0.723, 0.378, 0.98 };
int lda = 2;
double B[] = { 0.291, -0.267, -0.076, 0.103, -0.021, -0.866 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1725)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.771, 0.469, 0.822, -0.619, 0.953, -0.706, 0.318, 0.559, -0.68 };
int lda = 3;
double B[] = { -0.32, 0.362, 0.719, -0.661, -0.504, 0.595 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1726)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.073, -0.501, -0.561, -0.229, -0.533, -0.138, 0.924, -0.164, -0.023 };
int lda = 3;
double B[] = { -0.208, 0.49, 0.827, 0.641, -0.884, -0.624 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1727)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.33, -0.649, -0.43, -0.266, 0.787, 0.449, 0.435, -0.774, -0.447 };
int lda = 3;
double B[] = { -0.687, -0.459, 0.189, 0.762, -0.039, 0.047 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1728)");
}
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { 0.981, 0.242, 0.581, 0.064, 0.792, -0.529, 0.461, 0.224, -0.419 };
int lda = 3;
double B[] = { 0.285, 0.274, -0.912, 0.601, 0.24, 0.06 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1729)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.582, 0.269, -0.587, 0.68, -0.59, -0.936, 0.236, -0.728, -0.434 };
int lda = 3;
double B[] = { 0.113, 0.468, 0.943, 0.48, 0.215, -0.525 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1730)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.344, -0.938, 0.556, -0.678, -0.612, -0.519, -0.578, -0.848, 0.699 };
int lda = 3;
double B[] = { 0.915, -0.118, 0.538, -0.186, -0.413, -0.216 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1731)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.843, 0.54, -0.892, -0.296, 0.786, 0.136, 0.731, -0.418, -0.118 };
int lda = 3;
double B[] = { -0.775, 0.5, -0.399, -0.709, 0.779, 0.774 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1732)");
}
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha = 0;
double A[] = { -0.765, 0.233, 0.318, 0.547, -0.469, 0.023, -0.867, 0.687, -0.912 };
int lda = 3;
double B[] = { 0.019, -0.145, 0.472, 0.333, 0.527, -0.224 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_dtrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[i], B_expected[i], dbleps, "dtrmm(case 1733)");
}
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.852f, -0.409f, 0.871f, -0.854f, -0.493f, 0.444f, 0.973f, 0.027f };
int lda = 2;
float B[] = { -0.561f, 0.132f, 0.689f, 0.653f, -0.758f, -0.109f, -0.596f, 0.395f, -0.561f, 0.378f, 0.21f, 0.51f };
int ldb = 3;
float B_expected[] = { -0.0970014f, 0.0350174f, 0.0029825f, -0.048577f, -0.066776f, 0.121969f, -0.0368243f, -0.0590573f, -0.0352647f, -0.0556059f, -0.05019f, 0.019056f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1734) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1734) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.349f, 0.0f, -0.462f, 0.91f, -0.693f, 0.587f, -0.617f, 0.112f };
int lda = 2;
float B[] = { 0.842f, -0.473f, 0.825f, 0.866f, 0.986f, 0.686f, 0.346f, 0.299f, -0.659f, 0.009f, 0.007f, -0.478f };
int ldb = 3;
float B_expected[] = { 0.0296278f, 0.0410058f, -0.0262152f, 0.112127f, -0.0913206f, 0.141775f, -0.0299f, 0.0346f, -0.0009f, -0.0659f, 0.0478f, 0.0007f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1735) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1735) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.661f, -0.823f, 0.28f, 0.171f, 0.267f, 0.66f, 0.844f, 0.472f };
int lda = 2;
float B[] = { -0.256f, -0.518f, -0.933f, 0.066f, -0.513f, -0.286f, 0.109f, 0.372f, -0.183f, 0.482f, 0.362f, -0.436f };
int ldb = 3;
float B_expected[] = { 0.013171f, -0.059553f, -0.0811485f, -0.0562395f, -0.0233153f, -0.0574471f, -0.005815f, 0.018994f, 0.0277726f, -0.0674627f, 0.0612062f, 0.0563109f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1736) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1736) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.623f, 0.314f, -0.594f, 0.717f, 0.566f, 0.001f, -0.411f, -0.387f };
int lda = 2;
float B[] = { -0.083f, 0.937f, -0.814f, 0.9f, -0.042f, 0.678f, -0.928f, 0.228f, 0.965f, -0.16f, 0.006f, -0.281f };
int ldb = 3;
float B_expected[] = { -0.0937f, -0.0083f, -0.09f, -0.0814f, -0.0678f, -0.0042f, -0.0758259f, -0.0975915f, -0.0348586f, 0.0503376f, -0.0102706f, -0.001845f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1737) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1737) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.247f, -0.582f, 0.651f, -0.534f, -0.491f, 0.346f, 0.936f, -0.227f };
int lda = 2;
float B[] = { -0.002f, -0.02f, 0.162f, -0.62f, 0.632f, -0.07f, 0.352f, 0.042f, 0.574f, 0.272f, -0.139f, 0.012f };
int ldb = 2;
float B_expected[] = { -0.0366576f, 0.0123832f, 0.0617094f, 0.0010892f, 0.0249364f, -0.0384208f, 0.0040592f, 0.0339006f, 0.0455238f, 0.0080623f, -0.0042785f, -0.012738f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1738) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1738) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.152f, 0.395f, -0.077f, -0.191f, -0.757f, 0.858f, -0.494f, -0.734f };
int lda = 2;
float B[] = { -0.166f, -0.413f, -0.373f, 0.915f, -0.824f, -0.066f, -0.114f, -0.921f, 0.862f, 0.312f, 0.221f, 0.699f };
int ldb = 2;
float B_expected[] = { 0.142569f, -0.0668709f, -0.0915f, -0.0373f, -0.0533385f, 0.0052516f, 0.0921f, -0.0114f, 0.0027525f, 0.0094961f, -0.0699f, 0.0221f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1739) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1739) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.426f, 0.817f, -0.993f, -0.882f, 0.615f, 0.627f, -0.238f, -0.903f };
int lda = 2;
float B[] = { 0.895f, 0.849f, 0.811f, 0.402f, 0.074f, -0.493f, -0.548f, -0.82f, 0.323f, 0.301f, 0.612f, -0.092f };
int ldb = 2;
float B_expected[] = { -0.0369541f, -0.10749f, 0.246046f, 0.0030071f, -0.0270476f, 0.0371257f, -0.111428f, -0.111834f, -0.0135665f, -0.0383515f, 0.111452f, -0.0283989f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1740) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1740) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.451f, -0.754f, -0.673f, 0.433f, -0.712f, -0.033f, -0.588f, 0.116f };
int lda = 2;
float B[] = { 0.787f, -0.377f, -0.854f, -0.464f, 0.118f, 0.231f, 0.362f, -0.457f, -0.076f, 0.373f, -0.286f, -0.468f };
int ldb = 2;
float B_expected[] = { 0.0377f, 0.0787f, -0.0130492f, -0.122041f, -0.0231f, 0.0118f, 0.0561369f, 0.0182563f, -0.0373f, -0.0076f, 0.0751937f, -0.0396361f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1741) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1741) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.454f, 0.494f, 0.424f, -0.907f, 0.339f, -0.141f, 0.169f, 0.364f, -0.607f, 0.955f, -0.156f, 0.962f, -0.254f, 0.079f, 0.209f, 0.946f, 0.93f, 0.677f };
int lda = 3;
float B[] = { -0.99f, -0.484f, 0.915f, -0.383f, 0.228f, 0.797f, 0.597f, 0.765f, -0.629f, 0.002f, -0.89f, 0.077f };
int ldb = 3;
float B_expected[] = { 0.0269324f, 0.0688556f, -0.179902f, -0.104839f, -0.181106f, -0.0505677f, 0.0052392f, -0.0648948f, 0.0819028f, 0.132688f, 0.0961172f, -0.0473381f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1742) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1742) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.008f, -0.654f, 0.174f, 0.448f, 0.388f, -0.108f, -0.479f, -0.708f, -0.035f, 0.816f, 0.487f, 0.22f, -0.482f, 0.57f, -0.317f, 0.203f, -0.547f, -0.415f };
int lda = 3;
float B[] = { 0.651f, 0.187f, 0.591f, -0.007f, 0.171f, -0.923f, -0.029f, -0.685f, -0.049f, 0.135f, 0.578f, 0.979f };
int ldb = 3;
float B_expected[] = { -0.0187f, 0.0651f, -0.0317186f, 0.0620498f, 0.0794141f, 0.0733141f, 0.0685f, -0.0029f, -0.0002818f, 0.0252834f, -0.0771317f, 0.0439205f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1743) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1743) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.952f, 0.29f, 0.944f, 0.294f, -0.762f, -0.7f, -0.949f, 0.167f, 0.307f, 0.904f, -0.428f, -0.411f, 0.496f, 0.004f, -0.611f, -0.09f, -0.846f, 0.081f };
int lda = 3;
float B[] = { 0.782f, -0.035f, -0.441f, -0.791f, -0.09f, -0.56f, -0.438f, -0.691f, 0.88f, 0.545f, -0.55f, 0.595f };
int ldb = 3;
float B_expected[] = { -0.0592352f, 0.126282f, 0.0291241f, 0.0584267f, -0.046647f, 0.01215f, 0.0862177f, -0.14179f, -0.064879f, 0.016708f, 0.054792f, 0.0417105f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1744) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1744) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.519f, 0.708f, -0.934f, -0.219f, 0.376f, -0.967f, 0.322f, -0.355f, 0.972f, -0.156f, -0.735f, 0.928f, 0.084f, -0.267f, -0.152f, 0.434f, 0.267f, 0.983f };
int lda = 3;
float B[] = { -0.54f, 0.149f, 0.574f, 0.742f, 0.704f, 0.459f, -0.9f, 0.04f, 0.538f, -0.858f, 0.467f, 0.686f };
int ldb = 3;
float B_expected[] = { -0.0034742f, 0.0089927f, -0.0977768f, 0.0267786f, -0.0459f, 0.0704f, 0.0494331f, -0.0808964f, 0.0759594f, 0.0169292f, -0.0686f, 0.0467f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1745) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1745) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.541f, 0.67f, 0.014f, 0.446f, 0.086f, -0.525f, 0.033f, -0.932f, 0.977f, 0.321f, -0.651f, 0.027f, 0.409f, 0.328f, 0.359f, -0.615f, 0.419f, -0.25f };
int lda = 3;
float B[] = { -0.156f, 0.666f, -0.231f, 0.691f, 0.935f, -0.481f, -0.142f, -0.117f, 0.529f, 0.526f, 0.266f, 0.417f };
int ldb = 2;
float B_expected[] = { 0.0464826f, -0.0361824f, 0.0528601f, -0.0337999f, 0.0002432f, 0.168346f, -0.0078204f, 0.0535212f, 0.0438334f, 0.0110749f, -0.0360401f, -0.0228356f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1746) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1746) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.459f, -0.349f, -0.335f, 0.008f, 0.866f, 0.978f, -0.869f, -0.361f, -0.711f, 0.712f, 0.207f, 0.305f, 0.766f, -0.262f, 0.012f, -0.333f, 0.617f, 0.91f };
int lda = 3;
float B[] = { -0.138f, -0.256f, -0.319f, -0.771f, 0.674f, -0.565f, -0.779f, -0.516f, -0.017f, -0.097f, -0.555f, 0.308f };
int ldb = 2;
float B_expected[] = { 0.0256f, -0.0138f, 0.0771f, -0.0319f, 0.0292718f, 0.0701506f, -0.0269158f, -0.078012f, 0.0488162f, -0.0369837f, -0.0054207f, -0.118253f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1747) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1747) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.825f, -0.785f, -0.605f, -0.508f, 0.763f, -0.578f, -0.167f, -0.233f, 0.011f, -0.853f, 0.24f, 0.192f, 0.293f, -0.72f, -0.348f, 0.023f, -0.145f, -0.493f };
int lda = 3;
float B[] = { 0.305f, -0.255f, 0.882f, 0.883f, 0.088f, -0.473f, 0.135f, -0.063f, -0.671f, 0.473f, 0.874f, 0.548f };
int ldb = 2;
float B_expected[] = { -0.0961148f, -0.0983903f, 0.153836f, 0.0835432f, 0.0095579f, -0.0654357f, -0.018348f, 0.005229f, -0.0262218f, 0.0330484f, 0.0510342f, 0.0143434f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1748) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1748) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.63f, 0.353f, 0.445f, 0.845f, 0.273f, -0.135f, 0.03f, 0.936f, 0.141f, 0.638f, -0.399f, 0.343f, -0.037f, -0.335f, -0.089f, 0.081f, 0.987f, -0.256f };
int lda = 3;
float B[] = { -0.567f, 0.803f, 0.168f, 0.744f, -0.328f, 0.835f, -0.852f, 0.702f, 0.21f, -0.618f, 0.666f, -0.303f };
int ldb = 2;
float B_expected[] = { -0.0700351f, -0.144464f, -0.0163821f, -0.0663417f, -0.115361f, -0.0199816f, -0.105134f, -0.10138f, 0.0618f, 0.021f, 0.0303f, 0.0666f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1749) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1749) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.741f, 0.904f, -0.599f, 0.753f, -0.297f, 0.38f, -0.056f, -0.715f };
int lda = 2;
float B[] = { 0.646f, -0.447f, -0.147f, 0.314f, -0.713f, 0.187f, -0.589f, 0.287f, -0.809f, -0.293f, 0.418f, 0.778f };
int ldb = 3;
float B_expected[] = { -0.0915211f, -0.0074598f, 0.0365562f, -0.0174929f, 0.0783119f, 0.0359285f, -0.115925f, 0.0187826f, -0.0296066f, -0.031258f, 0.099134f, 0.0819138f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1750) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1750) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.645f, 0.756f, 0.709f, -0.657f, -0.023f, -0.714f, 0.03f, 0.239f };
int lda = 2;
float B[] = { -0.16f, 0.254f, -0.68f, 0.183f, -0.402f, -0.259f, 0.104f, -0.09f, 0.944f, 0.729f, -0.378f, -0.792f };
int ldb = 3;
float B_expected[] = { -0.0254f, -0.016f, -0.0183f, -0.068f, 0.0259f, -0.0402f, -0.0195206f, 0.0157438f, -0.130551f, 0.0582111f, 0.0711517f, -0.0833181f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1751) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1751) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.25f, -0.038f, 0.377f, -0.209f, 0.166f, -0.073f, -0.24f, 0.938f };
int lda = 2;
float B[] = { 0.26f, 0.696f, -0.183f, 0.668f, -0.08f, -0.938f, -0.837f, -0.509f, 0.781f, -0.063f, -0.953f, 0.227f };
int ldb = 3;
float B_expected[] = { -0.0140727f, -0.0084651f, -0.0106483f, 0.0104681f, 0.0124209f, -0.0197271f, 0.0662946f, 0.0678322f, -0.0747698f, -0.0128346f, 0.0948394f, 0.0015794f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1752) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1752) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.668f, 0.804f, 0.608f, -0.682f, -0.513f, 0.521f, 0.878f, -0.664f };
int lda = 2;
float B[] = { -0.871f, 0.699f, 0.561f, 0.823f, -0.787f, 0.055f, -0.686f, 0.361f, -0.662f, -0.192f, -0.301f, -0.167f };
int ldb = 3;
float B_expected[] = { -0.0156401f, -0.0707163f, -0.0576594f, 0.100064f, 0.001615f, -0.054558f, -0.0361f, -0.0686f, 0.0192f, -0.0662f, 0.0167f, -0.0301f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1753) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1753) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.091f, 0.189f, -0.221f, 0.749f, 0.354f, -0.397f, 0.105f, -0.944f };
int lda = 2;
float B[] = { 0.731f, -0.446f, 0.983f, 0.793f, 0.533f, 0.386f, -0.781f, -0.063f, 0.875f, -0.128f, -0.179f, -0.079f };
int ldb = 2;
float B_expected[] = { -0.0097573f, 0.0150815f, 0.129278f, 0.0933519f, -0.0135863f, -0.0024451f, -0.0655692f, 0.0200447f, -0.0153727f, 0.0103817f, 0.0232006f, 0.0165563f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1754) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1754) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.676f, 0.644f, 0.03f, 0.456f, 0.002f, -0.909f, 0.984f, 0.771f };
int lda = 2;
float B[] = { 0.65f, 0.005f, -0.883f, -0.154f, -0.137f, -0.137f, 0.531f, -0.49f, 0.052f, 0.273f, -0.602f, 0.655f };
int ldb = 2;
float B_expected[] = { -0.0005f, 0.065f, 0.074484f, -0.0877155f, 0.0137f, -0.0137f, 0.0365741f, 0.0406193f, -0.0273f, 0.0052f, -0.0608278f, -0.0353739f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1755) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1755) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.832f, -0.559f, 0.188f, -0.488f, -0.051f, -0.057f, 0.909f, 0.006f };
int lda = 2;
float B[] = { -0.408f, 0.303f, 0.03f, 0.529f, -0.584f, -0.976f, 0.443f, -0.762f, 0.43f, 0.812f, -0.075f, 0.06f };
int ldb = 2;
float B_expected[] = { -0.056498f, 0.0093713f, -0.0481041f, 0.0024096f, 0.0845016f, -0.132004f, 0.069f, 0.0407259f, -0.0483094f, 0.0826848f, -0.005409f, -0.0068535f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1756) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1756) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.15f, -0.297f, 0.821f, -0.576f, -0.572f, 0.924f, 0.106f, -0.131f };
int lda = 2;
float B[] = { -0.271f, 0.793f, -0.232f, -0.967f, -0.466f, 0.37f, -0.745f, -0.156f, -0.091f, -0.877f, 0.595f, 0.448f };
int ldb = 2;
float B_expected[] = { -0.0132725f, -0.101846f, 0.0967f, -0.0232f, -0.0671044f, -0.11675f, 0.0156f, -0.0745f, 0.0851912f, 0.0655543f, -0.0448f, 0.0595f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1757) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1757) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.002f, 0.0f, 0.626f, -0.148f, 0.874f, 0.229f, -0.227f, -0.55f, -0.895f, 0.586f, 0.934f, 0.618f, 0.958f, -0.543f, 0.49f, 0.671f, -0.871f, 0.227f };
int lda = 3;
float B[] = { -0.415f, 0.156f, -0.539f, -0.247f, -0.725f, 0.932f, 0.565f, 0.454f, -0.118f, 0.693f, -0.968f, -0.601f };
int ldb = 3;
float B_expected[] = { -0.0574005f, -0.122188f, -0.0327649f, -0.0625979f, 0.0976347f, 0.0419911f, 0.0294756f, -0.0678577f, 0.184894f, -0.0833182f, -0.0303735f, 0.0979555f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1758) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1758) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.89f, 0.309f, -0.786f, 0.999f, 0.511f, 0.599f, 0.385f, -0.615f, 0.527f, -0.328f, -0.078f, -0.666f, 0.004f, -0.69f, -0.281f, -0.438f, 0.456f, 0.524f };
int lda = 3;
float B[] = { -0.648f, -0.189f, -0.295f, 0.477f, 0.509f, 0.685f, 0.875f, 0.277f, -0.34f, -0.632f, -0.453f, -0.798f };
int ldb = 3;
float B_expected[] = { 0.0203701f, -0.104287f, -0.0084576f, 0.0121508f, -0.0685f, 0.0509f, 0.0245033f, 0.202013f, 0.0268058f, -0.0836134f, 0.0798f, -0.0453f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1759) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1759) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.772f, 0.686f, 0.693f, 0.803f, -0.328f, -0.627f, -0.869f, -0.656f, -0.055f, -0.366f, -0.981f, -0.151f, 0.147f, -0.368f, -0.824f, -0.454f, -0.445f, -0.794f };
int lda = 3;
float B[] = { -0.268f, -0.521f, -0.685f, -0.618f, 0.508f, 0.525f, -0.492f, -0.502f, -0.997f, 0.28f, 0.63f, 0.664f };
int ldb = 3;
float B_expected[] = { 0.058606f, 0.015051f, -0.0913257f, -0.0297397f, -0.0205282f, 0.0243534f, 0.0725056f, -0.0035452f, -0.110849f, 0.0255551f, 0.046652f, 0.0938454f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1760) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1760) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.317f, -0.822f, 0.732f, 0.383f, 0.457f, 0.443f, 0.529f, -0.949f, -0.927f, -0.65f, -0.471f, -0.624f, -0.731f, 0.107f, -0.142f, 0.623f, 0.159f, -0.419f };
int lda = 3;
float B[] = { 0.292f, -0.665f, -0.93f, 0.517f, 0.123f, -0.181f, 0.325f, 0.954f, -0.988f, -0.128f, 0.637f, -0.997f };
int ldb = 3;
float B_expected[] = { 0.0665f, 0.0292f, 0.0111893f, -0.140662f, 0.0316445f, -0.0209328f, -0.0954f, 0.0325f, -0.0068241f, 0.0089271f, 0.225695f, 0.0517387f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1761) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1761) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.809f, 0.393f, -0.015f, -0.273f, -0.956f, 0.49f, 0.365f, -0.386f, 0.941f, 0.992f, 0.297f, 0.761f, 0.425f, -0.605f, 0.672f, 0.725f, -0.077f, -0.628f };
int lda = 3;
float B[] = { 0.21f, 0.153f, 0.218f, -0.129f, 0.736f, -0.006f, 0.502f, -0.165f, 0.242f, 0.915f, 0.67f, 0.07f };
int ldb = 2;
float B_expected[] = { 0.0085068f, 0.069273f, 0.0439562f, 0.0320975f, -0.15148f, 0.0197777f, -0.0875509f, 0.103555f, 0.0222431f, 0.0555986f, 0.042615f, -0.000763f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1762) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1762) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.187f, -0.508f, -0.987f, -0.861f, 0.519f, 0.752f, -0.117f, 0.972f, 0.068f, -0.752f, 0.344f, 0.074f, -0.343f, 0.0f, -0.876f, 0.857f, -0.148f, -0.933f };
int lda = 3;
float B[] = { 0.827f, 0.958f, 0.395f, 0.878f, 0.88f, -0.896f, -0.771f, -0.355f, -0.979f, 0.329f, -0.166f, -0.644f };
int ldb = 2;
float B_expected[] = { -0.180535f, 0.193075f, -0.0391015f, 0.0887205f, 0.202321f, 0.145565f, -0.0066882f, -0.0073676f, -0.0329f, -0.0979f, 0.0644f, -0.0166f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1763) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1763) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { -0.622f, 0.022f, -0.966f, 0.704f, 0.43f, -0.451f, -0.221f, 0.969f, 0.977f, 0.021f, -0.725f, -0.382f, 0.779f, 0.957f, 0.25f, 0.832f, 0.029f, -0.903f };
int lda = 3;
float B[] = { 0.315f, -0.297f, -0.864f, 0.519f, -0.601f, -0.119f, 0.028f, 0.072f, -0.171f, 0.648f, 0.159f, -0.623f };
int ldb = 2;
float B_expected[] = { -0.0191664f, -0.0189396f, 0.0341826f, 0.052599f, -0.0379778f, -0.067988f, 0.103868f, 0.0495092f, -0.0219287f, 0.0971955f, -0.0388294f, -0.0688205f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1764) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1764) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.1f};
float A[] = { 0.106f, 0.87f, 0.21f, 0.463f, -0.496f, -0.981f, -0.354f, -0.604f, -0.149f, -0.384f, -0.958f, -0.502f, -0.579f, 0.736f, -0.322f, 0.028f, 0.193f, 0.14f };
int lda = 3;
float B[] = { -0.812f, 0.518f, 0.085f, -0.447f, -0.443f, 0.928f, -0.972f, 0.889f, 0.605f, -0.258f, -0.025f, 0.98f };
int ldb = 2;
float B_expected[] = { -0.0518f, -0.0812f, 0.0447f, 0.0085f, -0.0660824f, -0.0853354f, -0.0834485f, -0.0747189f, 0.0384994f, 0.240616f, -0.0754609f, 0.0871787f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1765) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1765) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.553f, 0.204f, -0.793f, -0.558f, 0.741f, 0.26f, 0.945f, -0.757f };
int lda = 2;
float B[] = { -0.515f, 0.532f, -0.321f, 0.326f, -0.81f, -0.924f, 0.474f, 0.985f, -0.03f, 0.406f, 0.923f, -0.956f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1766) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1766) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.41f, -0.804f, 0.988f, -0.715f, -0.281f, -0.89f, 0.389f, -0.408f };
int lda = 2;
float B[] = { 0.917f, 0.541f, -0.108f, -0.965f, 0.524f, 0.04f, -0.736f, -0.643f, -0.202f, 0.86f, 0.346f, -0.017f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1767) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1767) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { 0.153f, -0.812f, -0.742f, -0.18f, 0.473f, 0.023f, -0.433f, 0.559f };
int lda = 2;
float B[] = { 0.078f, -0.691f, -0.717f, -0.637f, -0.016f, 0.375f, -0.902f, -0.343f, 0.155f, 0.563f, 0.419f, 0.451f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1768) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1768) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.288f, 0.241f, 0.593f, -0.597f, -0.469f, 0.735f, 0.193f, -0.104f };
int lda = 2;
float B[] = { -0.835f, 0.037f, -0.762f, 0.782f, -0.874f, -0.867f, -0.81f, -0.577f, 0.352f, 0.827f, 0.237f, -0.861f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1769) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1769) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { 0.441f, -0.217f, 0.679f, 0.106f, -0.76f, -0.258f, -0.956f, -0.858f };
int lda = 2;
float B[] = { -0.802f, 0.163f, 0.293f, 0.54f, 0.228f, 0.071f, 0.942f, 0.345f, 0.591f, 0.654f, 0.382f, -0.892f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1770) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1770) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { 0.916f, 0.909f, 0.834f, 0.38f, 0.391f, -0.412f, -0.714f, -0.456f };
int lda = 2;
float B[] = { -0.151f, 0.818f, 0.717f, -0.812f, -0.649f, -0.107f, -0.454f, 0.785f, 0.86f, 0.992f, -0.244f, -0.242f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1771) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1771) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.992f, 0.284f, -0.01f, 0.182f, 0.527f, -0.348f, -0.509f, 0.839f };
int lda = 2;
float B[] = { 0.504f, -0.782f, -0.88f, 0.079f, 0.216f, 0.525f, 0.198f, 0.851f, -0.102f, -0.046f, 0.079f, -0.045f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1772) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1772) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { 0.985f, 0.068f, -0.095f, -0.575f, -0.607f, 0.893f, 0.085f, 0.145f };
int lda = 2;
float B[] = { -0.149f, 0.592f, 0.588f, -0.62f, -0.409f, -0.344f, 0.263f, 0.759f, -0.026f, -0.609f, 0.507f, -0.084f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1773) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1773) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { 0.36f, 0.508f, -0.771f, -0.442f, -0.671f, -0.691f, -0.771f, 0.113f, 0.282f, 0.312f, 0.564f, -0.568f, -0.743f, 0.912f, -0.395f, 0.503f, -0.167f, -0.581f };
int lda = 3;
float B[] = { -0.018f, 0.574f, -0.144f, -0.758f, 0.53f, 0.623f, -0.771f, -0.733f, 0.932f, -0.192f, 0.997f, 0.773f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1774) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1774) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.627f, 0.511f, -0.246f, -0.091f, 0.66f, -0.983f, 0.99f, 0.057f, -0.259f, 0.18f, 0.606f, 0.058f, -0.238f, 0.717f, 0.358f, -0.851f, -0.71f, -0.683f };
int lda = 3;
float B[] = { -0.907f, 0.956f, 0.56f, -0.057f, 0.054f, -0.77f, 0.868f, -0.843f, 0.645f, -0.554f, -0.958f, 0.988f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1775) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1775) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.882f, 0.431f, -0.868f, -0.098f, -0.006f, -0.639f, 0.757f, -0.009f, -0.821f, 0.45f, 0.347f, 0.801f, 0.314f, 0.936f, -0.725f, 0.956f, 0.536f, 0.771f };
int lda = 3;
float B[] = { 0.38f, -0.435f, 0.977f, 0.296f, -0.624f, -0.53f, 0.73f, -0.837f, 0.105f, 0.189f, 0.362f, -0.664f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1776) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1776) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { 0.595f, -0.775f, 0.75f, 0.16f, -0.572f, 0.658f, 0.216f, 0.557f, -0.279f, 0.095f, -0.495f, 0.503f, 0.071f, -0.03f, -0.116f, 0.78f, -0.104f, 0.073f };
int lda = 3;
float B[] = { 0.948f, 0.749f, -0.854f, 0.972f, 0.704f, 0.187f, 0.347f, 0.303f, -0.865f, 0.123f, -0.041f, 0.152f };
int ldb = 3;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1777) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1777) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.617f, -0.331f, -0.074f, 0.719f, -0.469f, -0.852f, 0.25f, -0.175f, -0.719f, -0.613f, -0.321f, 0.973f, -0.337f, -0.35f, 0.607f, -0.553f, 0.688f, 0.463f };
int lda = 3;
float B[] = { 0.568f, -0.471f, -0.947f, -0.205f, 0.835f, -0.859f, 0.27f, -0.599f, 0.171f, -0.514f, 0.939f, 0.176f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1778) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1778) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { 0.99f, -0.857f, 0.728f, -0.31f, -0.506f, -0.393f, 0.97f, 0.282f, 0.375f, -0.286f, -0.496f, -0.057f, 0.186f, -0.34f, 0.608f, -0.52f, 0.921f, -0.875f };
int lda = 3;
float B[] = { -0.929f, 0.885f, 0.864f, -0.548f, 0.393f, 0.391f, 0.033f, 0.186f, 0.949f, -0.435f, 0.986f, -0.995f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1779) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1779) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.101f, -0.92f, 0.969f, -0.017f, -0.016f, -0.024f, -0.11f, 0.219f, -0.287f, -0.937f, 0.619f, 0.166f, -0.068f, 0.753f, 0.374f, 0.076f, 0.79f, -0.64f };
int lda = 3;
float B[] = { 0.255f, 0.564f, -0.478f, -0.818f, -0.043f, 0.224f, -0.268f, 0.253f, 0.021f, 0.654f, 0.98f, -0.774f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1780) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1780) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
float alpha[2] = {0.0f, 0.0f};
float A[] = { -0.068f, -0.603f, -0.055f, 0.14f, 0.664f, 0.987f, 0.861f, -0.691f, -0.897f, -0.778f, 0.516f, -0.073f, -0.156f, -0.42f, 0.57f, 0.628f, 0.116f, 0.344f };
int lda = 3;
float B[] = { 0.922f, 0.39f, -0.724f, 0.421f, 0.418f, 0.92f, -0.222f, 0.835f, 0.417f, -0.392f, 0.012f, -0.346f };
int ldb = 2;
float B_expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
cblas_ctrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], flteps, "ctrmm(case 1781) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], flteps, "ctrmm(case 1781) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { 0.904, 0.243, 0.206, 0.68, -0.946, 0.946, -0.675, 0.729 };
int lda = 2;
double B[] = { 0.427, 0.116, 0.916, -0.384, -0.372, -0.754, 0.148, 0.089, -0.924, 0.974, -0.307, -0.55 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1782) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1782) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.898, 0.709, 0.719, -0.207, -0.841, -0.017, 0.202, -0.385 };
int lda = 2;
double B[] = { 0.308, 0.507, -0.838, 0.594, -0.811, 0.152, 0.118, -0.024, -0.632, 0.992, -0.942, 0.901 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1783) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1783) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.849, 0.455, -0.273, -0.668, 0.196, -0.985, -0.39, 0.564 };
int lda = 2;
double B[] = { -0.874, 0.188, -0.039, 0.692, 0.33, 0.119, 0.012, 0.425, 0.787, -0.918, 0.739, -0.871 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1784) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1784) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.325, 0.28, 0.902, -0.603, 0.091, -0.92, 0.209, -0.009 };
int lda = 2;
double B[] = { -0.202, -0.53, -0.88, -0.688, -0.215, 0.837, 0.917, 0.755, 0.477, 0.892, -0.524, -0.741 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1785) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1785) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.756, 0.874, 0.56, 0.157, -0.831, -0.991, -0.531, 0.813 };
int lda = 2;
double B[] = { 0.271, 0.783, -0.861, 0.635, -0.088, 0.434, 0.256, -0.34, -0.724, -0.277, -0.604, 0.986 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1786) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1786) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.371, -0.609, -0.812, -0.818, 0.45, -0.41, -0.704, -0.917 };
int lda = 2;
double B[] = { -0.268, 0.929, 0.82, 0.253, -0.883, 0.497, -0.265, 0.623, 0.131, -0.946, -0.365, 0.333 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1787) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1787) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.265, 0.8, -0.676, -0.592, 0.78, -0.838, -0.651, 0.115 };
int lda = 2;
double B[] = { 0.942, 0.692, -0.516, 0.378, 0.028, 0.265, 0.289, -0.721, -0.25, -0.952, 0.463, -0.34 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1788) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1788) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.852, -0.478, 0.16, 0.824, 0.073, 0.962, 0.509, -0.58 };
int lda = 2;
double B[] = { -0.789, 0.015, -0.779, -0.565, 0.048, -0.095, -0.272, 0.405, 0.272, 0.082, -0.693, -0.365 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1789) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1789) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { 0.251, 0.28, -0.092, 0.724, 0.928, -0.309, -0.222, -0.791, 0.113, -0.528, 0.148, 0.421, -0.833, 0.371, 0.354, 0.616, 0.313, 0.323 };
int lda = 3;
double B[] = { -0.769, -0.059, -0.068, 0.945, 0.938, -0.358, -0.17, 0.751, -0.248, -0.321, -0.818, 0.183 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1790) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1790) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.707, -0.802, 0.13, -0.19, -0.564, -0.74, 0.118, -0.194, -0.124, -0.421, 0.665, 0.308, 0.505, -0.278, 0.588, 0.957, -0.727, 0.976 };
int lda = 3;
double B[] = { 0.153, -0.09, -0.4, 0.669, 0.689, -0.238, -0.259, 0.891, 0.993, 0.996, -0.829, -0.736 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1791) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1791) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { 0.83, 0.316, -0.099, 0.824, 0.767, 0.662, 0.244, 0.872, 0.35, 0.969, -0.084, 0.907, -0.752, -0.675, 0.129, -0.649, -0.539, 0.969 };
int lda = 3;
double B[] = { -0.145, 0.254, -0.497, -0.713, -0.742, 0.183, 0.272, -0.858, -0.606, -0.605, -0.807, 0.686 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1792) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1792) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.091, 0.658, -0.834, -0.171, -0.126, -0.268, 0.879, -0.431, 0.678, -0.749, 0.136, -0.757, -0.578, 0.456, 0.978, -0.315, 0.333, 0.327 };
int lda = 3;
double B[] = { 0.963, -0.859, 0.599, 0.856, -0.924, 0.382, -0.531, 0.567, -0.454, 0.018, 0.97, 0.578 };
int ldb = 3;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1793) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1793) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.849, -0.819, 0.673, 0.574, -0.869, -0.969, -0.338, -0.097, -0.601, 0.903, 0.634, 0.313, 0.228, -0.028, 0.419, -0.762, 0.21, -0.532 };
int lda = 3;
double B[] = { -0.283, 0.999, -0.356, -0.459, 0.508, -0.132, -0.804, 0.173, 0.779, -0.427, 0.019, 0.347 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1794) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1794) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.117, -0.663, -0.95, -0.273, -0.497, -0.037, 0.084, -0.831, 0.023, -0.241, 0.063, -0.023, -0.498, -0.137, -0.77, 0.457, -0.021, -0.69 };
int lda = 3;
double B[] = { 0.308, -0.004, 0.013, 0.354, 0.077, -0.944, -0.877, 0.741, -0.807, -0.3, 0.891, -0.056 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1795) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1795) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.964, -0.653, 0.379, 0.994, -0.378, -0.409, 0.24, -0.333, 0.558, -0.099, -0.402, -0.812, 0.421, 0.823, -0.771, 0.998, 0.697, 0.253 };
int lda = 3;
double B[] = { 0.34, 0.479, 0.539, -0.133, 0.876, -0.347, 0.706, -0.623, 0.399, 0.903, -0.7, -0.088 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1796) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1796) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 111;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {0, 0};
double A[] = { -0.104, 0.643, -0.253, -0.988, -0.051, -0.805, 0.451, -0.421, -0.177, -0.534, -0.714, -0.581, -0.177, -0.582, -0.57, 0.259, -0.66, -0.864 };
int lda = 3;
double B[] = { 0.636, -0.365, -0.107, -0.279, 0.425, 0.976, 0.657, 0.294, 0.827, 0.187, 0.353, 0.31 };
int ldb = 2;
double B_expected[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1797) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1797) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.273, 0.812, 0.295, -0.415, -0.227, 0.901, 0.623, 0.786 };
int lda = 2;
double B[] = { -0.539, -0.551, -0.969, 0.09, -0.581, -0.594, -0.833, 0.457, -0.284, 0.434, -0.459, -0.662 };
int ldb = 3;
double B_expected[] = { -0.0312704, 0.2064538, 0.1775109, 0.1949157, -0.0337211, 0.2225517, 0.410638, -0.033917, 0.182384, -0.219409, 0.1257905, 0.1938415 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1798) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1798) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.323, 0.02, 0.718, 0.152, 0.665, 0.289, 0.317, 0.705 };
int lda = 2;
double B[] = { 0.448, -0.75, 0.851, 0.172, -0.244, 0.398, 0.602, 0.31, -0.017, 0.181, -0.119, 0.402 };
int ldb = 3;
double B_expected[] = { -0.0594, 0.2698, -0.2725, 0.0335, 0.0334, -0.1438, -0.2952588, 0.1518876, -0.213747, -0.073367, 0.0413388, -0.2306716 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1799) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1799) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.578, 0.018, -0.093, 0.964, 0.414, -0.729, 0.696, 0.874 };
int lda = 2;
double B[] = { -0.735, 0.788, -0.942, -0.71, -0.254, 0.265, 0.304, 0.218, 0.247, -0.172, 0.419, 0.448 };
int ldb = 3;
double B_expected[] = { -0.1486214, 0.2495598, -0.1744531, 0.0107667, -0.1648579, 0.1475263, -0.048058, -0.123122, -0.1062886, 0.0033742, -0.037823, -0.213397 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1800) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1800) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.358, -0.773, -0.065, 0.532, -0.319, 0.455, 0.578, 0.493 };
int lda = 2;
double B[] = { 0.744, -0.958, 0.162, 0.555, -0.131, 0.971, -0.467, 0.175, -0.794, 0.191, 0.361, 0.882 };
int ldb = 3;
double B_expected[] = { -0.1213734, 0.4492278, -0.1117944, -0.0070022, 0.108851, -0.320916, 0.1226, -0.0992, 0.2191, -0.1367, -0.1965, -0.2285 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1801) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1801) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.354, -0.504, -0.177, 0.186, -0.762, -0.506, 0.758, -0.994 };
int lda = 2;
double B[] = { -0.944, 0.562, 0.142, 0.742, 0.632, -0.627, -0.101, 0.476, 0.476, 0.675, 0.912, -0.33 };
int ldb = 2;
double B_expected[] = { -0.21291, -0.021306, -0.601736, 0.043676, 0.1715778, -0.0250026, 0.0587596, -0.2259812, -0.0036234, 0.1608258, 0.0885532, 0.6077736 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1802) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1802) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.001, 0.015, 0.942, 0.497, -0.104, 0.803, 0.679, 0.026 };
int lda = 2;
double B[] = { 0.889, -0.216, -0.912, -0.263, -0.329, 0.681, 0.332, -0.5, -0.484, 0.741, -0.728, -0.912 };
int ldb = 2;
double B_expected[] = { -0.2451, 0.1537, 0.2019693, -0.2251001, 0.0306, -0.2372, 0.1376892, 0.2324406, 0.0711, -0.2707, 0.5195777, 0.2860461 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1803) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1803) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.563, 0.394, -0.902, -0.27, 0.461, 0.939, -0.597, 0.803 };
int lda = 2;
double B[] = { 0.535, -0.111, 0.379, -0.036, 0.803, -0.341, 0.667, 0.001, 0.775, 0.714, 0.908, -0.508 };
int ldb = 2;
double B_expected[] = { 0.1623722, -0.1219324, 0.0266236, -0.1174842, 0.2429924, -0.1901218, 0.0662002, -0.2004014, 0.4905027, -0.2023089, -0.0629944, -0.3231352 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1804) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1804) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.159, 0.032, 0.785, 0.049, -0.128, 0.132, -0.735, -0.235 };
int lda = 2;
double B[] = { -0.331, -0.257, -0.725, 0.689, -0.793, 0.398, 0.127, -0.098, -0.498, -0.307, -0.019, 0.517 };
int ldb = 2;
double B_expected[] = { 0.2553318, -0.1678906, 0.1486, -0.2792, 0.1738216, -0.1670382, -0.0283, 0.0421, 0.151683, -0.083199, -0.046, -0.157 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1805) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1805) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.416, -0.424, -0.088, 0.614, -0.371, 0.983, -0.737, -0.647, 0.321, -0.518, 0.058, -0.533, 0.153, 0.283, 0.342, 0.993, -0.071, 0.225 };
int lda = 3;
double B[] = { -0.09, -0.844, -0.707, 0.903, 0.632, -0.294, -0.558, 0.74, -0.99, -0.855, -0.189, 0.543 };
int ldb = 3;
double B_expected[] = { 0.1668304, -0.2576208, -0.0664464, -0.0785782, -0.0226908, -0.0467944, -0.1091876, 0.3667652, 0.1076073, -0.1594011, 0.0407346, 0.0134478 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1806) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1806) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.67, -0.423, -0.165, 0.157, -0.43, 0.674, -0.35, 0.434, 0.972, -0.116, -0.029, 0.316, 0.914, 0.321, 0.132, 0.034, -0.907, -0.401 };
int lda = 3;
double B[] = { -0.396, 0.71, -0.588, 0.709, -0.024, -0.704, -0.988, 0.656, 0.665, -0.085, -0.778, 0.264 };
int ldb = 3;
double B_expected[] = { -0.1010812, -0.2287206, 0.0372688, -0.2530336, 0.0776, 0.2088, 0.264679, -0.133739, -0.147391, 0.161965, 0.207, -0.157 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1807) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1807) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.756, -0.149, -0.706, -0.162, -0.145, 0.67, 0.416, -0.27, -0.916, 0.995, -0.863, -0.25, -0.079, 0.248, -0.191, -0.195, 0.981, 0.834 };
int lda = 3;
double B[] = { 0.329, 0.921, -0.018, -0.02, 0.095, -0.892, -0.105, -0.799, -0.583, 0.564, -0.436, 0.965 };
int ldb = 3;
double B_expected[] = { -0.1805114, -0.1555812, -0.1560482, -0.0462226, -0.0967127, 0.2921239, 0.1183692, 0.1566766, 0.2260429, 0.3915667, 0.1788155, -0.2682995 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1808) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1808) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.552, -0.668, -0.013, 0.088, -0.766, 0.977, 0.088, -0.06, -0.311, 0.872, -0.328, -0.01, 0.659, -0.327, -0.276, 0.553, -0.734, -0.079 };
int lda = 3;
double B[] = { -0.87, 0.728, 0.997, -0.36, -0.046, -0.505, 0.082, -0.787, 0.414, 0.965, -0.048, -0.591 };
int ldb = 3;
double B_expected[] = { 0.1882, -0.3054, -0.2648624, 0.1695328, 0.0462155, -0.3187195, 0.0541, 0.2443, -0.2012812, -0.2298476, 0.3871505, 0.2622315 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1809) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1809) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.349, -0.072, 0.545, 0.212, -0.306, -0.009, 0.757, -0.925, 0.159, 0.308, 0.476, 0.1, 0.725, -0.757, -0.245, 0.571, 0.515, 0.993 };
int lda = 3;
double B[] = { 0.865, 0.501, 0.165, -0.63, -0.513, 0.351, -0.521, -0.062, 0.54, -0.634, -0.719, 0.216 };
int ldb = 2;
double B_expected[] = { -0.054193, 0.023274, 0.1487731, -0.3509657, -0.0481592, -0.1044386, 0.0666567, 0.1890461, -0.2932696, 0.0278532, 0.2357046, 0.1223408 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1810) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1810) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.941, -0.496, 0.492, 0.356, 0.353, 0.346, -0.519, -0.86, -0.677, -0.154, 0.313, 0.228, -0.56, -0.451, -0.78, 0.174, -0.663, 0.22 };
int lda = 3;
double B[] = { 0.162, -0.345, 0.188, 0.578, -0.675, 0.775, -0.018, 0.198, -0.222, -0.52, 0.672, -0.438 };
int ldb = 2;
double B_expected[] = { -0.3430472, 0.0394834, 0.0185782, -0.1505014, 0.0092108, -0.3837276, 0.0741276, -0.2435652, 0.1186, 0.1338, -0.1578, 0.1986 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1811) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1811) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.592, 0.708, 0.442, 0.212, 0.815, -0.638, 0.55, -0.512, -0.487, 0.181, 0.708, -0.126, 0.408, -0.51, 0.175, 0.114, -0.919, -0.268 };
int lda = 3;
double B[] = { 0.858, -0.004, 0.59, -0.395, -0.943, 0.824, 0.01, 0.455, -0.775, 0.062, -0.644, 0.03 };
int ldb = 2;
double B_expected[] = { -0.21374, -0.130452, -0.20707, 0.00773, -0.16787, 0.186571, -0.05026, 0.106515, -0.2887485, -0.0045065, -0.2446935, 0.1590455 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1812) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1812) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 112;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.988, -0.915, 0.963, 0.103, 0.921, 0.555, 0.846, 0.148, -0.43, 0.336, -0.371, 0.381, -0.487, 0.717, 0.881, -0.777, 0.774, -0.962 };
int lda = 3;
double B[] = { -0.805, 0.605, 0.481, 0.163, -0.057, -0.017, -0.886, 0.809, 0.875, 0.905, 0.095, 0.894 };
int ldb = 2;
double B_expected[] = { 0.181, -0.262, -0.1606, -0.0008, 0.220089, -0.234263, 0.0303246, -0.3486122, -0.0476352, -0.3174616, -0.2077412, -0.1552106 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1813) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1813) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.513, -0.385, -0.524, 0.726, 0.823, 0.839, -0.355, -0.881 };
int lda = 2;
double B[] = { -0.707, 0.016, 0.481, 0.935, 0.052, 0.719, 0.277, 0.169, 0.894, 0.352, -0.216, -0.741 };
int ldb = 3;
double B_expected[] = { -0.078919, 0.119774, 0.2114654, 0.0276682, 0.12593, 0.074299, -0.109352, -0.193196, 0.077864, 0.032876, -0.3330992, 0.2249494 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1814) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1814) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.136, -0.37, 0.669, -0.731, -0.4, 0.638, 0.833, -0.29 };
int lda = 2;
double B[] = { -0.861, -0.278, 0.941, 0.822, 0.88, 0.501, 0.911, -0.502, 0.573, -0.498, -0.517, -0.518 };
int ldb = 3;
double B_expected[] = { 0.2861, -0.0027, -0.3645, -0.1525, -0.3141, -0.0623, -0.0297254, 0.4490328, -0.254473, -0.161772, 0.0423084, -0.1675858 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1815) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1815) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.641, -0.058, 0.246, 0.884, -0.686, 0.123, -0.869, 0.891 };
int lda = 2;
double B[] = { 0.107, -0.333, 0.556, 0.124, 0.206, 0.049, -0.573, -0.9, -0.417, -0.734, -0.719, 0.76 };
int ldb = 3;
double B_expected[] = { -0.1591469, -0.1071617, -0.2301499, -0.1454657, -0.1758188, 0.1884616, -0.0380754, -0.4181892, -0.013453, -0.33198, -0.3886102, 0.1361404 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1816) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1816) imag");
};
};
};
{
int order = 101;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.083, 0.441, 0.995, 0.338, -0.988, -0.828, -0.254, -0.036 };
int lda = 2;
double B[] = { -0.792, 0.552, 0.033, -0.178, -0.225, 0.553, 0.348, 0.229, -0.151, -0.594, 0.711, -0.335 };
int ldb = 3;
double B_expected[] = { 0.3362416, -0.3167112, -0.2305904, -0.0177512, 0.0477576, -0.5068152, -0.1273, -0.0339, 0.1047, 0.1631, -0.1798, 0.1716 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1817) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1817) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.105, 0.584, -0.33, -0.182, -0.096, -0.257, 0.327, -0.123 };
int lda = 2;
double B[] = { -0.249, -0.274, -0.197, -0.899, 0.85, -0.318, 0.596, -0.237, 0.179, 0.046, -0.859, -0.459 };
int ldb = 2;
double B_expected[] = { 0.0441837, -0.0536099, -0.0065547, 0.1208159, 0.0819176, 0.1492908, -0.0917294, -0.0510192, -0.0037271, 0.0344777, 0.0974489, 0.0389047 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1818) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1818) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.972, 0.794, -0.968, -0.406, -0.2, -0.512, 0.436, 0.161 };
int lda = 2;
double B[] = { 0.817, -0.17, -0.613, -0.565, -0.494, 0.129, -0.593, -0.516, -0.695, -0.42, 0.848, 0.122 };
int ldb = 2;
double B_expected[] = { -0.2281, 0.1327, 0.2180776, -0.0351272, 0.1353, -0.0881, 0.2475472, 0.1823936, 0.2505, 0.0565, -0.345628, 0.165156 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1819) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1819) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.373, -0.316, -0.052, 0.025, -0.878, 0.612, 0.486, 0.953 };
int lda = 2;
double B[] = { -0.626, 0.408, 0.536, 0.66, -0.666, -0.127, 0.622, 0.036, -0.761, 0.773, -0.137, 0.074 };
int ldb = 2;
double B_expected[] = { 0.1214746, -0.0093742, -0.247838, 0.145962, 0.0994439, 0.0586017, -0.043453, 0.206241, 0.1510011, -0.0661437, -0.0178345, -0.0495635 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1820) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1820) imag");
};
};
};
{
int order = 102;
int side = 141;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.621, -0.252, -0.942, 0.073, 0.416, -0.724, -0.972, 0.028 };
int lda = 2;
double B[] = { -0.006, 0.427, 0.292, -0.212, -0.319, -0.08, -0.401, 0.465, -0.493, -0.529, 0.003, -0.19 };
int ldb = 2;
double B_expected[] = { 0.0284232, -0.2112704, -0.0664, 0.0928, 0.0210696, 0.1558958, 0.0738, -0.1796, 0.1879327, 0.0541021, 0.0181, 0.0573 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1821) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1821) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.415, 0.215, 0.507, 0.094, 0.697, 0.633, 0.206, -0.383, -0.974, 0.734, -0.533, -0.15, -0.982, -0.232, -0.297, 0.501, -0.092, 0.663 };
int lda = 3;
double B[] = { 0.812, 0.323, 0.294, -0.423, -0.85, 0.043, -0.338, -0.568, 0.976, -0.375, 0.913, -0.119 };
int ldb = 3;
double B_expected[] = { 0.2153111, -0.0775367, 0.0404927, -0.0287599, -0.0879721, -0.1572073, -0.2481947, 0.2941819, 0.5234716, -0.1242382, 0.108305, 0.162022 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1822) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1822) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.827, -0.754, 0.719, 0.88, -0.942, -0.152, 0.051, 0.033, -0.603, -0.557, 0.668, 0.024, 0.082, 0.458, 0.733, 0.669, 0.722, -0.661 };
int lda = 3;
double B[] = { -0.523, 0.365, -0.811, -0.632, -0.06, 0.151, -0.962, -0.71, -0.543, 0.8, -0.264, 0.994 };
int ldb = 3;
double B_expected[] = { 0.4413193, -0.3047431, 0.307206, 0.074162, 0.0029, -0.0513, 0.2285887, 0.1349491, 0.061616, -0.510648, -0.0202, -0.3246 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1823) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1823) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.958, 0.948, -0.161, -0.34, -0.184, 0.43, -0.045, -0.465, -0.278, 0.461, 0.584, 0.003, -0.794, -0.778, -0.65, -0.91, 0.24, -0.944 };
int lda = 3;
double B[] = { 0.279, 0.041, -0.033, 0.332, 0.788, 0.611, -0.644, -0.133, 0.247, 0.06, 0.125, -0.407 };
int ldb = 3;
double B_expected[] = { -0.0693236, 0.0981792, -0.0442625, -0.0021815, 0.1936084, -0.3409328, 0.174601, -0.219233, 0.0274565, 0.1321885, -0.2252264, 0.1381888 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1824) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1824) imag");
};
};
};
{
int order = 101;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.983, -0.795, -0.115, -0.542, 0.837, 0.518, -0.164, 0.776, -0.453, -0.28, 0.135, -0.377, -0.199, -0.965, 0.784, -0.39, -0.499, 0.257 };
int lda = 3;
double B[] = { -0.712, 0.364, -0.28, 0.05, 0.314, 0.748, -0.719, 0.619, 0.474, -0.906, -0.859, 0.943 };
int ldb = 3;
double B_expected[] = { 0.1772, -0.1804, -0.0900512, -0.1509216, 0.0485292, 0.0109956, 0.1538, -0.2576, -0.2767208, 0.2420976, 0.2164354, 0.0610082 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1825) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1825) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.105, 0.503, -0.17, 0.2, -0.861, -0.279, -0.231, 0.058, 0.699, 0.437, 0.578, 0.462, 0.473, -0.793, -0.34, -0.162, -0.128, -0.844 };
int lda = 3;
double B[] = { -0.802, 0.292, -0.155, -0.916, -0.099, -0.082, 0.057, 0.215, 0.94, 0.911, -0.714, 0.41 };
int ldb = 2;
double B_expected[] = { -0.1044001, -0.5102243, 0.3865174, 0.0189802, 0.1888166, -0.0057672, -0.0800722, 0.0699214, 0.199086, -0.291946, 0.141904, 0.171064 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1826) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1826) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 121;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.468, 0.378, -0.498, 0.251, 0.777, -0.543, -0.913, 0.095, 0.779, -0.933, 0.068, -0.669, 0.715, 0.03, 0.012, 0.392, -0.785, -0.056 };
int lda = 3;
double B[] = { 0.143, -0.242, -0.379, -0.831, -0.46, -0.663, -0.735, -0.098, -0.861, -0.894, 0.772, -0.059 };
int ldb = 2;
double B_expected[] = { 0.0633681, 0.0476643, -0.1761819, 0.3044093, 0.2798556, 0.0187868, 0.2647924, 0.0455132, 0.3477, 0.1821, -0.2257, 0.0949 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1827) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1827) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 131;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { -0.764, 0.908, 0.899, 0.119, -0.447, 0.279, 0.338, 0.73, -0.74, -0.366, -0.572, 0.583, 0.75, 0.519, 0.603, 0.831, 0.697, 0.822 };
int lda = 3;
double B[] = { 0.399, 0.572, -0.489, 0.964, -0.167, -0.104, 0.75, -0.199, 0.777, 0.503, -0.025, -0.386 };
int ldb = 2;
double B_expected[] = { 0.015568, 0.261244, -0.345424, 0.212636, -0.2247824, -0.0859342, 0.1074596, -0.4846822, -0.2415227, 0.2465939, 0.2042976, 0.2206978 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1828) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1828) imag");
};
};
};
{
int order = 102;
int side = 142;
int uplo = 122;
int trans = 113;
int diag = 132;
int M = 2;
int N = 3;
double alpha[2] = {-0.3, 0.1};
double A[] = { 0.432, 0.063, 0.065, -0.546, 0.099, 0.892, 0.48, -0.085, 0.746, -0.541, -0.739, -0.207, 0.695, 0.765, 0.197, -0.86, 0.621, -0.653 };
int lda = 3;
double B[] = { 0.182, 0.731, 0.571, 0.01, -0.357, -0.612, 0.581, 0.756, -0.911, -0.225, 0.438, 0.546 };
int ldb = 2;
double B_expected[] = { -0.1277, -0.2011, -0.1723, 0.0541, 0.2698001, 0.0651043, -0.2906381, -0.2592593, -0.0512125, -0.0040605, 0.0647965, 0.1119875 };
cblas_ztrmm(order, side, uplo, trans, diag, M, N, alpha, A, lda, B, ldb);
{
int i;
for (i = 0; i < 6; i++) {
gsl_test_rel(B[2*i], B_expected[2*i], dbleps, "ztrmm(case 1829) real");
gsl_test_rel(B[2*i+1], B_expected[2*i+1], dbleps, "ztrmm(case 1829) imag");
};
};
};
}
| {
"alphanum_fraction": 0.5185736234,
"avg_line_length": 31.3247213779,
"ext": "c",
"hexsha": "328163e7e1769dbd4c568d6f4b6b2412690d1cd5",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-10-02T01:32:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-10-02T01:32:59.000Z",
"max_forks_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ICML14MoMCompare/spectral-learn",
"max_forks_repo_path": "code/em/treba/gsl-1.0/cblas/test_trmm.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ICML14MoMCompare/spectral-learn",
"max_issues_repo_path": "code/em/treba/gsl-1.0/cblas/test_trmm.c",
"max_line_length": 177,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "91e70bc88726ee680ec6e8cbc609977db3fdcff9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ICML14MoMCompare/spectral-learn",
"max_stars_repo_path": "code/em/treba/gsl-1.0/cblas/test_trmm.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z",
"num_tokens": 60285,
"size": 123670
} |
#pragma once
#include "errors.h"
#include "usageinfoformat.h"
#include "detail/config.h"
#include "detail/configmacro.h"
#include "detail/configaccess.h"
#include "detail/flag.h"
#include <gsl/gsl>
#include <iostream>
#include <ostream>
#include <optional>
#include <map>
#include <utility>
namespace cmdlime{
enum class ErrorOutputMode{
STDOUT,
STDERR
};
template<typename TConfig>
class ConfigReader{
struct CommandHelpFlag{
bool value = false;
std::string usageInfo;
};
public:
ConfigReader(TConfig& cfg,
std::string programName,
const UsageInfoFormat& usageInfoFormat = {},
ErrorOutputMode errorOutputMode = ErrorOutputMode::STDERR)
: cfg_(cfg)
, programName_(std::move(programName))
, usageInfoFormat_(usageInfoFormat)
, errorOutput_(errorOutputMode == ErrorOutputMode::STDERR ? std::cerr : std::cout)
{}
int exitCode() const
{
return exitCode_;
}
bool read(const std::vector<std::string>& cmdLine)
{
addExitFlags();
if(!processCommandLine(cmdLine))
return exitOnError(-1);
if (processFlagsAndExit())
return exitOnFlag();
return success();
}
bool readCommandLine(int argc, char** argv)
{
auto cmdLine = std::vector<std::string>(argv + 1, argv + argc);
return read(cmdLine);
}
private:
void addExitFlags()
{
using NameProvider = typename detail::Format<detail::ConfigAccess<TConfig>::format()>::nameProvider;
auto helpFlag = std::make_unique<detail::Flag>(NameProvider::name("help"),
std::string{},
[this]()->bool&{return help_;},
detail::Flag::Type::Exit);
helpFlag->info().addDescription("show usage info and exit");
detail::ConfigAccess<TConfig>{cfg_}.addFlag(std::move(helpFlag));
if (!cfg_.versionInfo().empty()){
auto versionFlag = std::make_unique<detail::Flag>(NameProvider::name("version"),
std::string{},
[this]()->bool&{return version_;},
detail::Flag::Type::Exit);
versionFlag->info().addDescription("show version info and exit");
detail::ConfigAccess<TConfig>{cfg_}.addFlag(std::move(versionFlag));
}
detail::ConfigAccess<TConfig>(cfg_).addHelpFlagToCommands(programName_);
}
bool processCommandLine(const std::vector<std::string>& cmdLine)
{
try{
cfg_.read(cmdLine);
}
catch(const CommandError& e){
errorOutput_ << "Command '" + e.commandName() + "' error: " << e.what() << "\n";
std::cout << e.commandUsageInfo() << std::endl;
return false;
}
catch(const Error& e){
errorOutput_ << e.what() << "\n";
std::cout << cfg_.usageInfo(programName_) << std::endl;
return false;
}
return true;
}
bool processFlagsAndExit()
{
if (help_){
std::cout << cfg_.usageInfoDetailed(programName_, usageInfoFormat_) << std::endl;
return true;
}
if (version_){
std::cout << cfg_.versionInfo() << std::endl;
return true;
}
for (auto command : detail::ConfigAccess<TConfig>{cfg_}.commandList())
if (checkCommandHelpFlag(command))
return true;
return false;
}
bool checkCommandHelpFlag(gsl::not_null<detail::ICommand*> command)
{
if (command->isHelpFlagSet()){
std::cout << command->usageInfoDetailed() << std::endl;
return true;
}
for (auto childCommand : command->commandList())
if (checkCommandHelpFlag(childCommand))
return true;
return false;
}
bool exitOnFlag()
{
exitCode_ = 0;
return false;
}
bool exitOnError(int errorCode)
{
exitCode_ = errorCode;
return false;
}
bool success()
{
exitCode_ = 0;
return true;
}
private:
TConfig& cfg_;
std::string programName_;
UsageInfoFormat usageInfoFormat_;
std::map<int, CommandHelpFlag> commandHelpFlags_;
std::ostream& errorOutput_;
int exitCode_ = 0;
bool help_ = false;
bool version_ = false;
}
;
}
| {
"alphanum_fraction": 0.5458646617,
"avg_line_length": 28.0421686747,
"ext": "h",
"hexsha": "2a3cdd02716a3f57b512f3f02bdd121ea34ec15c",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-05-22T00:36:08.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-05-22T00:36:08.000Z",
"max_forks_repo_head_hexsha": "0058bffd31fd2a46374fd44c6730c2356bbaab43",
"max_forks_repo_licenses": [
"MS-PL"
],
"max_forks_repo_name": "GerHobbelt/hypertextcpp",
"max_forks_repo_path": "thirdparty/cmdlime/include/cmdlime/configreader.h",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "0058bffd31fd2a46374fd44c6730c2356bbaab43",
"max_issues_repo_issues_event_max_datetime": "2021-12-21T08:13:28.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-05-20T22:04:52.000Z",
"max_issues_repo_licenses": [
"MS-PL"
],
"max_issues_repo_name": "GerHobbelt/hypertextcpp",
"max_issues_repo_path": "thirdparty/cmdlime/include/cmdlime/configreader.h",
"max_line_length": 108,
"max_stars_count": 77,
"max_stars_repo_head_hexsha": "0058bffd31fd2a46374fd44c6730c2356bbaab43",
"max_stars_repo_licenses": [
"MS-PL"
],
"max_stars_repo_name": "GerHobbelt/hypertextcpp",
"max_stars_repo_path": "thirdparty/cmdlime/include/cmdlime/configreader.h",
"max_stars_repo_stars_event_max_datetime": "2022-02-13T21:37:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-20T18:05:54.000Z",
"num_tokens": 1015,
"size": 4655
} |
#include <math.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_multimin.h>
#include <gsl/gsl_sf.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_linalg.h>
#include <getopt.h>
#include <string.h>
/******************************************************************************/
#define H 0.5
#define maxnd 2000
#define neutral 0
#define selected 1
#define max_n_int_evaluated 1000
#define max_n_s_evaluated 2000
#define undefined -99999999999.99
#define undefined_int 999999
#define max_str_len 100
#define n_decimal_places 6
#define max_s_ranges 100
#define s_evaluated_vec_file_const "s_evaluated.dat"
#define t2_evaluated_vec_file_const "t2_evaluated.dat"
#define n2_evaluated_vec_file_const "n2_evaluated.dat"
#define s_range_file_const "s_ranges_evaluated.dat"
#define phase_1_dir_const "n1_n2_t2_s_vec_dir"
#define phase_2_dir_const "n2_t2_s_vec_dir"
#define const_pop_file "control_generate_allele_distrib_n1.out.bin"
/******************************************************************************/
/*Function List*/
double compute_weighted_average(double *weighted_vec, double *phase1_mut_vec,
double *phase2_mut_vec, int n1d, int n2d);
float assign_float_from_read_buff(char *buffer, int start);
int get_average_egf_vecs_1_and_2(double s,int n1, int n2, double t2_real,
int t2_lower, int t2_upper, double *egf_vec, char *buffer_p1_n2_t2_lower,
char *buffer_p2_n2_t2_lower, char *buffer_p1_n2_t2_upper,
char *buffer_p2_n2_t2_upper);
get_upper_lower_int(double parm, int *lower, int *upper, int n_int_evaluated, int *int_evaluated_vec);
get_upper_lower_double(double parm, double*lower, double *upper,int n_int_evaluated, double *double_evaluated_vec);
get_s_ranges();
get_int_evaluated_vec(int *int_evaluated_vec, int *n_int_evaluated,
int *int_lower, int *int_step, char *int_evaluated_vec_file);
scale_vector(double *vec, int n2, double total_density_s0);
int get_binary_egf_vec(char *buffer, int n, int t2, double s, double *egf_vec);
fold_vector_double(double *vec, int counter);
fold_vector_int(int *vec, int counter);
int nearest_n2_ind(int n2_real);
read_phase1_phase2_file_into_buffer(int n1, int phase, int n2, int t2, char *buffer,
int file_size_bytes);
read_const_pop_file_into_buffer(int n1, char *buffer, int file_size_bytes);
compute_weighted_average_egf_vec(double t2_real, int t2_lower, int t2_upper,
double *egf_vec_lower, double *egf_vec_upper,
double *egf_vec, int n2d);
double compute_weighted_average(double *weighted_vec, double *phase1_mut_vec,
double *phase2_mut_vec, int n1d, int n2d);
int get_const_pop_egf_vec(double s, int n1, double *egf_vec, char *buffer_const_pop,
int assign_tds0_mode);
assign_int_from_read_buff(int *res, char *buffer, int start);
float assign_float_from_read_buff(char *buffer, int start);
int compute_s_tab_num(double s);
int compute_file_size_bytes(int n);
set_up_file_name(int n1, char *froot, char *file_name);
get_data_path(char *data_path);
get_s_evaluated_vec(double *s_evaluated_vec, int *n_s_evaluated,
int *n_s_evaluated_file, char *s_evaluated_vec_file);
get_lower_upper(int ind, double *s_evaluated_vec, int n_s_evaluated,
double *lower, double *upper);
dumpvector(double *v, int min, int max, char *s);
dumpmatrix(double **m, int s1,
int rows, int s2, int cols, char *s);
double selfn(double q, double s, double h);
setuprow(double **a, double p, int row, int n);
setupmatrix(double **a, int n1, int n2, double s, double h);
matrixinvert(int N, double **a,double *inverter);
tmiterate(double **a,double *mut1,
int t, int n1, int n2,int decay,double *sumf);
tmiterate2(double **a,double *mut1,
int t, int n1, int n2,int decay,double **a1);
eqf_using_matrix_inversion(int n1,double s,double **a,double *egf_out);
vector_average(int n1,int n2,double *fv1,double *fv2, double *fv_out);
vector_s_average(int n,double P1,double *fv1,double *fv2, double *fv_out);
output_sfs_to_file_thanasis_format(int n, int *sfs1,int *sfs2,char *sfs_filename);
output_sfs_to_file_peter_format(int n,int sample1, int sample2, int *sfs1,int *sfs2,char *sfs_filename);
get_sfs(int alleles,int *par,char *sfs_filename);
get_sfs_peter1(int *total_neu,int *total_sel,int *nalleles,int *sfs_sel,int *sfs_neu,char *sfs_filename);
get_sfs_peter2(int *total_neu,int *total_sel,int *nalleles,int *sfs_sel,int *sfs_neu,char *sfs_filename,int *sel_sites,int *sel_diff,int *neu_sites,int *neu_diff);
int binarysearchcumulative_from_zero(double *array, int size);
double randomly_select_allele_frequency(double *egf_vec, double *temp1, int nd);
set_up_cumulative_allele_freq_vec(int nd, double *egf_vec, double *cum_vec,
char *str);
generate_simulated_data(double *egf_vec, int nsites, int sample_size, int nd,
int *sfs);
egf_scaling_s(int n1,double f0,double *v_s_in, double *v_s_out);
egf_scaling_f0(int n1,double f0,double *fv);
egf_scaling(int N,double f0,double *FV0,double *FVS);
binomial_sampling(int n1,int alleles,int sample, double *invy,int *discrete);
int set_up_density_vec_equal_effects(double s, int n_s_evaluated, double *gamma_density_vec);
int set_up_density_vec_step_effects(double alpha, double beta, int n_s_evaluated, double *gamma_density_vec);
double compute_beta_densities(double alpha, double *s_evaluated_vec,
int n_s_evaluated, double *gamma_density_vec, double beta);
double compute_gamma_densities(double alpha, double *s_evaluated_vec,
int n_s_evaluated, double *gamma_density_vec, double beta);
double calculate_ne(int n1,int n2,int t);
/******************************************************************************/
/*Structure List*/
struct rangestruct
{
double s_lower, s_upper, s_step;
int s_lower_index;
};
struct rangestruct s_ranges[max_s_ranges+1];
/******************************************************************************/
/*Global variable List*/
double allele_freq_sampled[maxnd+1];
double total_density_s0;
char s_evaluated_vec_file[max_str_len], t2_evaluated_vec_file[max_str_len],
n2_evaluated_vec_file[max_str_len], s_range_file[max_str_len],
phase_1_dir[max_str_len], phase_2_dir[max_str_len],
const_pop_dir[max_str_len];
char data_path[max_str_len], file_label_str[max_str_len];
int nranges, trace_level, n_sfs;
int n_s_evaluated, n_s_evaluated_file, gss_n2;
int t2_evaluated_vec[max_n_int_evaluated], n_t2_evaluated, t2_lower;
int t2_step, verbose_mode, neutrals_only_mode;
int n2_evaluated_vec[max_n_int_evaluated], n_n2_evaluated, n2_lower;
double s_evaluated_vec[max_n_s_evaluated];
/******************************************************************************/
| {
"alphanum_fraction": 0.7408984146,
"avg_line_length": 45.1125827815,
"ext": "h",
"hexsha": "bc08fc3a25bac45f26c3d3504f0def567d1ff9a0",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0cb64ad4955eaa861a08233fcdd70e59ec15c350",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kousathanas/simsfs_fast",
"max_forks_repo_path": "Library_DFE_v1.8.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0cb64ad4955eaa861a08233fcdd70e59ec15c350",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "kousathanas/simsfs_fast",
"max_issues_repo_path": "Library_DFE_v1.8.h",
"max_line_length": 163,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0cb64ad4955eaa861a08233fcdd70e59ec15c350",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kousathanas/simsfs_fast",
"max_stars_repo_path": "Library_DFE_v1.8.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1845,
"size": 6812
} |
// MIT License
//
// Copyright (c) 2020 SunnyCase
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include <chino/ddk/kernel.h>
#include <cstdint>
#include <gsl/gsl-lite.hpp>
#include <xmmintrin.h>
namespace chino::arch
{
// No asynchronous interrupt is supported by this target
// Only save callee saved registers in context
struct win32_thread_context
{
uintptr_t rbx;
uintptr_t rbp;
uintptr_t rdi;
uintptr_t rsi;
uintptr_t rsp;
uintptr_t r12;
uintptr_t r13;
uintptr_t r14;
uintptr_t r15;
uintptr_t reserved0;
__m128 xmm6;
__m128 xmm7;
__m128 xmm8;
__m128 xmm9;
__m128 xmm10;
__m128 xmm11;
__m128 xmm12;
__m128 xmm13;
__m128 xmm14;
__m128 xmm15;
uintptr_t stack_low;
uintptr_t stack_high;
};
using thread_context_t = win32_thread_context;
struct win32_arch
{
static constexpr size_t ALLOCATE_ALIGNMENT = 16;
static uint32_t current_processor() noexcept { return 0; }
static void yield_processor() noexcept;
static uintptr_t disable_irq() noexcept;
static void restore_irq(uintptr_t state) noexcept;
static void init_thread_context(thread_context_t &context, gsl::span<uintptr_t> stack, kernel::thread_thunk_t start, void *arg0, void *arg1) noexcept;
[[noreturn]] static void start_schedule(thread_context_t &context) noexcept;
static void yield(thread_context_t &old_context, thread_context_t &new_context) noexcept;
static void init_stack_check() noexcept;
};
using arch_t = win32_arch;
}
| {
"alphanum_fraction": 0.74395947,
"avg_line_length": 31.6790123457,
"ext": "h",
"hexsha": "39ee7e26d1a444ed0909deb70ed590056d14105c",
"lang": "C",
"max_forks_count": 20,
"max_forks_repo_forks_event_max_datetime": "2021-09-13T10:14:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-05-18T03:54:08.000Z",
"max_forks_repo_head_hexsha": "e4b444983a059231636b81dc5f33206e16a859c2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dotnetGame/chino-os",
"max_forks_repo_path": "src/hal/include/chino/arch/win32/arch.h",
"max_issues_count": 7,
"max_issues_repo_head_hexsha": "e4b444983a059231636b81dc5f33206e16a859c2",
"max_issues_repo_issues_event_max_datetime": "2020-04-30T14:46:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-05-15T02:15:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dotnetGame/chino-os",
"max_issues_repo_path": "src/hal/include/chino/arch/win32/arch.h",
"max_line_length": 154,
"max_stars_count": 137,
"max_stars_repo_head_hexsha": "e4b444983a059231636b81dc5f33206e16a859c2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "chino-os/chino-os",
"max_stars_repo_path": "src/hal/include/chino/arch/win32/arch.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-10T11:42:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-04-28T09:50:17.000Z",
"num_tokens": 614,
"size": 2566
} |
/* ode-initval/gear1.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* 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 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
* 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.
*/
/* Gear 1. This is the implicit Euler a.k.a backward Euler method. */
/* Author: G. Jungman
*/
/* Error estimation by step doubling, see eg. Ascher, U.M., Petzold,
L.R., Computer methods for ordinary differential and
differential-algebraic equations, SIAM, Philadelphia, 1998.
The method is also described in eg. this reference.
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_odeiv.h>
#include "odeiv_util.h"
typedef struct
{
double *k;
double *y0;
double *y0_orig;
double *y_onestep;
}
gear1_state_t;
static void *
gear1_alloc (size_t dim)
{
gear1_state_t *state = (gear1_state_t *) malloc (sizeof (gear1_state_t));
if (state == 0)
{
GSL_ERROR_NULL ("failed to allocate space for gear1_state", GSL_ENOMEM);
}
state->k = (double *) malloc (dim * sizeof (double));
if (state->k == 0)
{
free (state);
GSL_ERROR_NULL ("failed to allocate space for k", GSL_ENOMEM);
}
state->y0 = (double *) malloc (dim * sizeof (double));
if (state->y0 == 0)
{
free (state->k);
free (state);
GSL_ERROR_NULL ("failed to allocate space for y0", GSL_ENOMEM);
}
state->y0_orig = (double *) malloc (dim * sizeof (double));
if (state->y0_orig == 0)
{
free (state->y0);
free (state->k);
free (state);
GSL_ERROR_NULL ("failed to allocate space for y0_orig", GSL_ENOMEM);
}
state->y_onestep = (double *) malloc (dim * sizeof (double));
if (state->y_onestep == 0)
{
free (state->y0_orig);
free (state->y0);
free (state->k);
free (state);
GSL_ERROR_NULL ("failed to allocate space for y_onestep", GSL_ENOMEM);
}
return state;
}
static int
gear1_step (double *y, gear1_state_t *state,
const double h, const double t,
const size_t dim, const gsl_odeiv_system *sys)
{
/* Makes an implicit Euler advance with step size h.
y0 is the initial values of variables y.
The implicit matrix equations to solve are:
k = y0 + h * f(t + h, k)
y = y0 + h * f(t + h, k)
*/
const int iter_steps = 3;
int nu;
size_t i;
double *y0 = state->y0;
double *k = state->k;
/* Iterative solution of k = y0 + h * f(t + h, k)
Note: This method does not check for convergence of the
iterative solution!
*/
for (nu = 0; nu < iter_steps; nu++)
{
int s = GSL_ODEIV_FN_EVAL(sys, t + h, y, k);
if (s != GSL_SUCCESS)
{
return s;
}
for (i=0; i<dim; i++)
{
y[i] = y0[i] + h * k[i];
}
}
return GSL_SUCCESS;
}
static int
gear1_apply(void * vstate,
size_t dim,
double t,
double h,
double y[],
double yerr[],
const double dydt_in[],
double dydt_out[],
const gsl_odeiv_system * sys)
{
gear1_state_t *state = (gear1_state_t *) vstate;
size_t i;
double *y0 = state->y0;
double *y0_orig = state->y0_orig;
double *y_onestep = state->y_onestep;
/* initialization */
DBL_MEMCPY(y0, y, dim);
/* Save initial values for possible failures */
DBL_MEMCPY (y0_orig, y, dim);
/* First traverse h with one step (save to y_onestep) */
DBL_MEMCPY (y_onestep, y, dim);
{
int s = gear1_step (y_onestep, state, h, t, dim, sys);
if (s != GSL_SUCCESS)
{
return s;
}
}
/* Then with two steps with half step length (save to y) */
{
int s = gear1_step (y, state, h / 2.0, t, dim, sys);
if (s != GSL_SUCCESS)
{
/* Restore original y vector */
DBL_MEMCPY (y, y0_orig, dim);
return s;
}
}
DBL_MEMCPY (y0, y, dim);
{
int s = gear1_step (y, state, h / 2.0, t + h / 2.0, dim, sys);
if (s != GSL_SUCCESS)
{
/* Restore original y vector */
DBL_MEMCPY (y, y0_orig, dim);
return s;
}
}
/* Cleanup update */
if (dydt_out != NULL)
{
int s = GSL_ODEIV_FN_EVAL (sys, t + h, y, dydt_out);
if (s != GSL_SUCCESS)
{
/* Restore original y vector */
DBL_MEMCPY (y, y0_orig, dim);
return s;
}
}
/* Error estimation */
for (i = 0; i < dim; i++)
{
yerr[i] = 4.0 * (y[i] - y_onestep[i]);
}
return GSL_SUCCESS;
}
static int
gear1_reset (void *vstate, size_t dim)
{
gear1_state_t *state = (gear1_state_t *) vstate;
DBL_ZERO_MEMSET (state->y_onestep, dim);
DBL_ZERO_MEMSET (state->y0_orig, dim);
DBL_ZERO_MEMSET (state->y0, dim);
DBL_ZERO_MEMSET (state->k, dim);
return GSL_SUCCESS;
}
static unsigned int
gear1_order (void *vstate)
{
gear1_state_t *state = (gear1_state_t *) vstate;
state = 0; /* prevent warnings about unused parameters */
return 1;
}
static void
gear1_free (void *vstate)
{
gear1_state_t *state = (gear1_state_t *) vstate;
free (state->y_onestep);
free (state->y0_orig);
free (state->y0);
free (state->k);
free (state);
}
static const gsl_odeiv_step_type gear1_type = { "gear1", /* name */
0, /* can use dydt_in? */
1, /* gives exact dydt_out? */
&gear1_alloc,
&gear1_apply,
&gear1_reset,
&gear1_order,
&gear1_free
};
const gsl_odeiv_step_type *gsl_odeiv_step_gear1 = &gear1_type;
| {
"alphanum_fraction": 0.6030435486,
"avg_line_length": 22.6263736264,
"ext": "c",
"hexsha": "1111bd3fdc1cec328910ecc167ec572606215c5e",
"lang": "C",
"max_forks_count": 14,
"max_forks_repo_forks_event_max_datetime": "2020-03-12T12:31:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T04:47:52.000Z",
"max_forks_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Brian-ning/HMNE",
"max_forks_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/ode-initval/gear1.c",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e",
"max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "Brian-ning/HMNE",
"max_issues_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/ode-initval/gear1.c",
"max_line_length": 81,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ielomariala/Hex-Game",
"max_stars_repo_path": "gsl-2.6/ode-initval/gear1.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z",
"num_tokens": 1868,
"size": 6177
} |
/*
** generate permutation table using exchangeability information
**
** G.Lohmann, July 2018
*/
#include <viaio/Vlib.h>
#include <viaio/file.h>
#include <viaio/option.h>
#include <viaio/mu.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
extern gsl_matrix *XRead2ndLevel(VString);
extern void XReadExchange(VString filename,int *exchange,int n);
extern gsl_matrix *PseudoInv(gsl_matrix *A,gsl_matrix *B);
void genperm(long seed,int *exchange,int signswitch,
int **permtable,int **signtable,int nimages,int numperm,gsl_vector *contrast)
{
int i,j,k,m,kmax;
/* ini permutation and sign-switching tables */
for (i = 0; i < numperm; i++) {
permtable[i] = (int *) VCalloc(nimages,sizeof(int));
signtable[i] = (int *) VCalloc(nimages,sizeof(int));
for (j=0; j<nimages; j++) permtable[i][j] = j;
for (j=0; j<nimages; j++) signtable[i][j] = 1;
}
/* ini random number generator */
gsl_rng_env_setup();
const gsl_rng_type *T = gsl_rng_default;
gsl_rng *rx = gsl_rng_alloc(T);
gsl_rng_set(rx,(unsigned long int)seed);
/* sign switching only */
if (signswitch >= 0) {
for (i=0; i<numperm; i++) {
for (j=0; j<nimages; j++) {
if (gsl_ran_bernoulli (rx,(double)0.5) == 1) signtable[i][j] = -1;
}
}
return; /* stop here, no permutations */
}
/* get max number of exchange groups */
kmax=0;
for (j=0; j<nimages; j++) {
if (exchange[j] > kmax) kmax = exchange[j];
}
/* permutations of rows of the design matrix */
int *base = (int *) VCalloc(nimages,sizeof(int));
for (i = 0; i < numperm; i++) {
/* for each group */
for (k=0; k<=kmax; k++) {
m = 0;
for (j=0; j<nimages; j++) {
if (exchange[j] == k) {
base[m] = j;
m++;
}
}
if (m < 1) continue;
/* random shuffle within group */
gsl_ran_shuffle (rx, base, m, sizeof (int));
m = 0;
for (j=0; j<nimages; j++) {
if (exchange[j] == k) {
permtable[i][j] = base[m];
m++;
}
}
}
}
VFree(base);
}
/* for zero variance replace permutations with sign switching (only for non-nuisance columns) */
int SignSwitch (gsl_matrix *X,gsl_vector *contrast,int *permflag)
{
int i,j;
double s1=0,s2=0,nx=0,u=0,mean=0,var=0;
int signswitch = -1;
for (j=0; j<X->size2; j++) {
if (permflag[j] == 0) continue;
if (fabs(contrast->data[j]) < TINY) continue;
s1 = s2 = nx = 0;
for (i=0; i<X->size1; i++) {
u = gsl_matrix_get(X,i,j);
s1 += u;
s2 += u*u;
nx++;
}
mean = s1/nx;
var = (s2 - nx * mean * mean) / (nx - 1.0);
if (var < TINY && signswitch >= 0)
VError(" Implausible design, two columns have zero variance: %d %d",signswitch+1,j+1);
if (var < TINY) signswitch = j;
}
return signswitch;
}
| {
"alphanum_fraction": 0.5920964501,
"avg_line_length": 23.6984126984,
"ext": "c",
"hexsha": "034e707ff6853bbf04358971e8ba44587ee3df30",
"lang": "C",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2022-03-22T08:05:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-09-29T10:33:53.000Z",
"max_forks_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zrajna/lipsia",
"max_forks_repo_path": "src/stats/vlisa_2ndlevel/genperm.c",
"max_issues_count": 7,
"max_issues_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014",
"max_issues_repo_issues_event_max_datetime": "2022-02-16T13:42:05.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-11-12T15:47:56.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zrajna/lipsia",
"max_issues_repo_path": "src/stats/vlisa_2ndlevel/genperm.c",
"max_line_length": 96,
"max_stars_count": 17,
"max_stars_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zrajna/lipsia",
"max_stars_repo_path": "src/stats/vlisa_2ndlevel/genperm.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-18T10:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-10T16:33:42.000Z",
"num_tokens": 991,
"size": 2986
} |
#ifndef _COSMOLOGY_H_
#define _COSMOLOGY_H_
#include <gsl/gsl_integration.h>
class cosmology{
double Om_M, Om_L, Om_b, Om_c, tau, T_CMB, h;
double E(double z);
static double E_inv(double z, void *params);
static double rd_int(double z, void *params);
static double rz(double z, void *params);
double Theta();
double k_eq();
public:
cosmology(double H_0 = 70.0, double OmegaM = 0.3, double OmegaL = 0.7, double Omegab = 0.04,
double Omegac = 0.26, double Tau = 0.066, double TCMB = 2.718);
double Omega_M();
double Omega_L();
double Omega_bh2();
double Omega_ch2();
double h_param();
double H0();
double H(double z);
double D_A(double z);
double D_V(double z);
double z_eq();
double z_d();
double R(double z);
double r_d();
double comoving_distance(double z, gsl_integration_workspace *w);
};
#endif
| {
"alphanum_fraction": 0.5127753304,
"avg_line_length": 20.2678571429,
"ext": "h",
"hexsha": "29f75d486e41e7066454efaca9d964ef3e76a219",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5c805a432d948490290d209c1856fdb0bc9d1b8d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dpearson1983/CUBE",
"max_forks_repo_path": "include/cosmology.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5c805a432d948490290d209c1856fdb0bc9d1b8d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dpearson1983/CUBE",
"max_issues_repo_path": "include/cosmology.h",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5c805a432d948490290d209c1856fdb0bc9d1b8d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dpearson1983/CUBE",
"max_stars_repo_path": "include/cosmology.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 285,
"size": 1135
} |
/* sys/infnan.c
*
* Copyright (C) 2001, 2004, 2007, 2010 Brian Gough
*
* 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 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
* 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.
*/
#include <config.h>
#include <math.h>
#if HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
#include <gsl/gsl_sys.h>
double gsl_nan (void)
{
return gsl_fdiv (0.0, 0.0);
}
double gsl_posinf (void)
{
return gsl_fdiv (+1.0, 0.0);
}
double gsl_neginf (void)
{
return gsl_fdiv (-1.0, 0.0);
}
int gsl_isnan (const double x);
int gsl_isinf (const double x);
int gsl_finite (const double x);
#if defined(_MSC_VER) /* Microsoft Visual C++ */
#include <float.h>
int
gsl_isnan (const double x)
{
return _isnan(x);
}
int
gsl_isinf (const double x)
{
int fpc = _fpclass(x);
if (fpc == _FPCLASS_PINF)
return +1;
else if (fpc == _FPCLASS_NINF)
return -1;
else
return 0;
}
int
gsl_finite (const double x)
{
return _finite(x);
}
#else
# if HAVE_DECL_ISFINITE
int
gsl_finite (const double x)
{
return isfinite(x);
}
# elif HAVE_DECL_FINITE
int
gsl_finite (const double x)
{
return finite(x);
}
# elif HAVE_IEEE_COMPARISONS
int
gsl_finite (const double x)
{
const double y = x - x;
int status = (y == y);
return status;
}
# else
# error "cannot define gsl_finite without HAVE_DECL_FINITE or HAVE_IEEE_COMPARISONS"
# endif
# if HAVE_DECL_ISNAN
int
gsl_isnan (const double x)
{
return isnan(x);
}
#elif HAVE_IEEE_COMPARISONS
int
gsl_isnan (const double x)
{
int status = (x != x);
return status;
}
# else
# error "cannot define gsl_isnan without HAVE_DECL_ISNAN or HAVE_IEEE_COMPARISONS"
# endif
# if HAVE_DECL_ISINF
int
gsl_isinf (const double x)
{
/* isinf(3): In glibc 2.01 and earlier, isinf() returns a
non-zero value (actually: 1) if x is an infinity (positive or
negative). (This is all that C99 requires.) */
if (isinf(x))
{
return (x > 0) ? 1 : -1;
}
else
{
return 0;
}
}
# else
int
gsl_isinf (const double x)
{
if (! gsl_finite(x) && ! gsl_isnan(x))
{
return (x > 0 ? +1 : -1);
}
else
{
return 0;
}
}
# endif
#endif
| {
"alphanum_fraction": 0.670793882,
"avg_line_length": 17.9477124183,
"ext": "c",
"hexsha": "aee48ceec6f608f3cd2569967285147b67a52eed",
"lang": "C",
"max_forks_count": 173,
"max_forks_repo_forks_event_max_datetime": "2022-03-27T07:27:04.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-08T18:01:54.000Z",
"max_forks_repo_head_hexsha": "47849f0443b890c4a875360f881d2e60d1cba630",
"max_forks_repo_licenses": [
"Net-SNMP",
"Xnet"
],
"max_forks_repo_name": "juandesant/astrometry.net",
"max_forks_repo_path": "gsl-an/sys/infnan.c",
"max_issues_count": 208,
"max_issues_repo_head_hexsha": "47849f0443b890c4a875360f881d2e60d1cba630",
"max_issues_repo_issues_event_max_datetime": "2022-03-25T15:21:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-08T20:26:38.000Z",
"max_issues_repo_licenses": [
"Net-SNMP",
"Xnet"
],
"max_issues_repo_name": "juandesant/astrometry.net",
"max_issues_repo_path": "gsl-an/sys/infnan.c",
"max_line_length": 84,
"max_stars_count": 460,
"max_stars_repo_head_hexsha": "47849f0443b890c4a875360f881d2e60d1cba630",
"max_stars_repo_licenses": [
"Net-SNMP",
"Xnet"
],
"max_stars_repo_name": "juandesant/astrometry.net",
"max_stars_repo_path": "gsl-an/sys/infnan.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-29T00:37:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-06T13:20:04.000Z",
"num_tokens": 858,
"size": 2746
} |
/**
*
* @file zgesdd.c
*
* PLASMA computational routines
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Azzam Haidar
* @date 2010-11-15
* @precisions normal z -> s d c
*
**/
#include <lapacke.h>
#include "common.h"
#define COMPLEX
/***************************************************************************//**
*
* @ingroup PLASMA_Complex64_t
*
* PLASMA_zgesdd - computes the singular value decomposition (SVD) of a complex
* M-by-N matrix A, optionally computing the left and/or right singular
* vectors, by using divide-and-conquer method. The SVD is written
*
* A = U * SIGMA * conjugate-transpose(V)
*
* where SIGMA is an M-by-N matrix which is zero except for its
* min(m,n) diagonal elements, U is an M-by-M unitary matrix, and
* V is an N-by-N unitary matrix. The diagonal elements of SIGMA
* are the singular values of A; they are real and non-negative, and
* are returned in descending order. The first min(m,n) columns of
* U and V are the left and right singular vectors of A.
*
* Note that the routine returns VT = V**H, not V.
*
* The divide and conquer algorithm makes very mild assumptions about
* floating point arithmetic. It will work on machines with a guard
* digit in add/subtract, or on those binary machines without guard
* digits which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or
* Cray-2. It could conceivably fail on hexadecimal or decimal machines
* without guard digits, but we know of none.
*
* NOTE that the input parameter of this function differ from the
* LAPACK ZGESDD. We have jobu and jobvt instead of only jobz first
* to be consistent with ZGESVD and second to allow a computation
* of only U or VT.
*******************************************************************************
*
* @param[in] jobu
* Specifies options for computing all or part of the matrix U.
* Intended usage:
* = PlasmaVec = 'A'(lapack): all M columns of U are returned
* in array U;
* = PlasmaNoVec = 'N': no columns of U (no left singular vectors)
* are computed.
* = PlasmaSVec = 'S': the first min(m,n) columns of U (the left
* singular vectors) are returned in the array U;
* NOT SUPPORTTED YET
* = PlasmaOVec = 'O': the first min(m,n) columns of U (the left
* singular vectors) are overwritten on the array A;
* NOT SUPPORTTED YET
*
* @param[in] jobvt
* Specifies options for computing all or part of the matrix V**H.
* Intended usage:
* = PlasmaVec = 'A'(lapack): all N rows of V**H are returned
* in the array VT;
* = PlasmaNoVec = 'N': no rows of V**H (no right singular vectors)
* are computed.
* = PlasmaSVec = 'S': the first min(m,n) rows of V**H (the right
* singular vectors) are returned in the array VT;
* NOT SUPPORTTED YET
* = PlasmaOVec = 'O': the first min(m,n) rows of V**H (the right
* singular vectors) are overwritten on the array A;
* NOT SUPPORTTED YET
*
* Note: jobu and jobvt cannot both be PlasmaOVec.
*
* @param[in] M
* The number of rows of the matrix A. M >= 0.
*
* @param[in] N
* The number of columns of the matrix A. N >= 0.
*
* @param[in,out] A
* On entry, the M-by-N matrix A.
* On exit,
* if JOBU = 'O', A is overwritten with the first min(m,n)
* columns of U (the left singular vectors,
* stored columnwise);
* if JOBVT = 'O', A is overwritten with the first min(m,n)
* rows of V**H (the right singular vectors,
* stored rowwise);
* if JOBU .ne. 'O' and JOBVT .ne. 'O', the contents of A
* are destroyed.
*
* @param[in] LDA
* The leading dimension of the array A. LDA >= max(1,M).
*
* @param[out] S
* The double precision singular values of A, sorted so that S(i) >= S(i+1).
*
* @param[in, out] descT
* On entry, descriptor as return by PLASMA_Alloc_Workspace_zgesdd
* On exit, contains auxiliary factorization data.
*
* @param[out] U
* (LDU,M) if JOBU = 'A' or (LDU,min(M,N)) if JOBU = 'S'.
* If JOBU = 'A', U contains the M-by-M unitary matrix U;
* if JOBU = 'S', U contains the first min(m,n) columns of U
* (the left singular vectors, stored columnwise);
* if JOBU = 'N' or 'O', U is not referenced.
*
* @param[in] LDU
* The leading dimension of the array U. LDU >= 1; if
* JOBU = 'S' or 'A', LDU >= M.
*
* @param[out] VT
* If JOBVT = 'A', VT contains the N-by-N unitary matrix
* V**H;
* if JOBVT = 'S', VT contains the first min(m,n) rows of
* V**H (the right singular vectors, stored rowwise);
* if JOBVT = 'N' or 'O', VT is not referenced.
*
* @param[in] LDVT
* The leading dimension of the array VT. LDVT >= 1; if
* JOBVT = 'A', LDVT >= N; if JOBVT = 'S', LDVT >= min(M,N).
*
*******************************************************************************
*
* @return
* \retval PLASMA_SUCCESS successful exit
* \retval <0 if -i, the i-th argument had an illegal value
*
*******************************************************************************
*
* @sa PLASMA_zgesdd_Tile
* @sa PLASMA_zgesdd_Tile_Async
* @sa PLASMA_cgesdd
* @sa PLASMA_dgesdd
* @sa PLASMA_sgesdd
*
******************************************************************************/
int PLASMA_zgesdd(PLASMA_enum jobu, PLASMA_enum jobvt, int M, int N,
PLASMA_Complex64_t *A, int LDA,
double *S,
PLASMA_desc *descT,
PLASMA_Complex64_t *U, int LDU,
PLASMA_Complex64_t *VT, int LDVT)
{
int NB;
int status;
plasma_context_t *plasma;
PLASMA_sequence *sequence = NULL;
PLASMA_request request = PLASMA_REQUEST_INITIALIZER;
PLASMA_desc descA;
plasma = plasma_context_self();
if (plasma == NULL) {
plasma_fatal_error("PLASMA_zgesdd", "PLASMA not initialized");
return PLASMA_ERR_NOT_INITIALIZED;
}
/* Check input arguments */
if (jobu != PlasmaNoVec && jobu !=PlasmaVec) {
plasma_error("PLASMA_zgesdd", "illegal value of jobu");
return -1;
}
if (jobvt != PlasmaNoVec && jobvt != PlasmaVec) {
plasma_error("PLASMA_zgesdd", "illegal value of jobvt");
return -2;
}
if (jobvt != jobu) {
plasma_error("PLASMA_zgesdd", "in this version: jobu should be equal jobvt");
return -22;
}
if (M < 0) {
plasma_error("PLASMA_zgesdd", "illegal value of M");
return -3;
}
if (N < 0) {
plasma_error("PLASMA_zgesdd", "illegal value of N");
return -4;
}
if (LDA < max(1, M)) {
plasma_error("PLASMA_zgesdd", "illegal value of LDA");
return -6;
}
if (LDU < 1) {
plasma_error("PLASMA_zgesdd", "illegal value of LDU");
return -9;
}
if (LDVT < 1) {
plasma_error("PLASMA_zgesdd", "illegal value of LDVT");
return -11;
}
/* Quick return */
if (min(M, N) == 0) {
return PLASMA_SUCCESS;
}
/* Tune NB & IB depending on M & N; Set NBNB */
status = plasma_tune(PLASMA_FUNC_ZGESVD, M, N, 0);
if (status != PLASMA_SUCCESS) {
plasma_error("PLASMA_zgesdd", "plasma_tune() failed");
return status;
}
/* Set MT, NT */
NB = PLASMA_NB;
plasma_sequence_create(plasma, &sequence);
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
plasma_zooplap2tile( descA, A, NB, NB, LDA, N, 0, 0, M, N, sequence, &request,
plasma_desc_mat_free(&(descA)) );
} else {
plasma_ziplap2tile( descA, A, NB, NB, LDA, N, 0, 0, M, N,
sequence, &request);
}
/* Call the tile interface */
PLASMA_zgesdd_Tile_Async(jobu, jobvt, &descA, S, descT, U, LDU, VT, LDVT, sequence, &request);
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
plasma_zooptile2lap( descA, A, NB, NB, LDA, N, sequence, &request);
plasma_dynamic_sync();
plasma_desc_mat_free(&descA);
} else {
plasma_ziptile2lap( descA, A, NB, NB, LDA, N, sequence, &request);
plasma_dynamic_sync();
}
status = sequence->status;
plasma_sequence_destroy(plasma, sequence);
return status;
}
/***************************************************************************//**
*
* @ingroup PLASMA_Complex64_t_Tile
*
* PLASMA_zgesdd_Tile - computes the singular value decomposition (SVD) of a complex
* M-by-N matrix A, optionally computing the left and/or right singular
* vectors.
* Tile equivalent of PLASMA_zgesdd().
* Operates on matrices stored by tiles.
* All matrices are passed through descriptors.
* All dimensions are taken from the descriptors.
*
*******************************************************************************
*
* @param[in] jobu
* Specifies options for computing all or part of the matrix U.
* Intended usage:
* = PlasmaVec = 'A'(lapack): all M columns of U are returned
* in array U;
* = PlasmaNoVec = 'N': no columns of U (no left singular vectors)
* are computed.
* = PlasmaSVec = 'S': the first min(m,n) columns of U (the left
* singular vectors) are returned in the array U;
* NOT SUPPORTTED YET
* = PlasmaOVec = 'O': the first min(m,n) columns of U (the left
* singular vectors) are overwritten on the array A;
* NOT SUPPORTTED YET
*
* @param[in] jobvt
* Specifies options for computing all or part of the matrix V**H.
* Intended usage:
* = PlasmaVec = 'A'(lapack): all N rows of V**H are returned
* in the array VT;
* = PlasmaNoVec = 'N': no rows of V**H (no right singular vectors)
* are computed.
* = PlasmaSVec = 'S': the first min(m,n) rows of V**H (the right
* singular vectors) are returned in the array VT;
* NOT SUPPORTTED YET
* = PlasmaOVec = 'O': the first min(m,n) rows of V**H (the right
* singular vectors) are overwritten on the array A;
* NOT SUPPORTTED YET
*
* Note: jobu and jobvt cannot both be PlasmaOVec.
*
* @param[in,out] A
* On entry, the M-by-N matrix A.
* On exit,
* if JOBU = 'O', A is overwritten with the first min(m,n)
* columns of U (the left singular vectors,
* stored columnwise);
* if JOBVT = 'O', A is overwritten with the first min(m,n)
* rows of V**H (the right singular vectors,
* stored rowwise);
* if JOBU .ne. 'O' and JOBVT .ne. 'O', the contents of A
* are destroyed.
*
* @param[out] S
* The singular values of A, sorted so that S(i) >= S(i+1).
*
* @param[in, out] T
* On entry, descriptor as return by PLASMA_Alloc_Workspace_zgesdd
* On exit, contains auxiliary factorization data.
*
* @param[out] U
* (LDU,M) if JOBU = 'A' or (LDU,min(M,N)) if JOBU = 'S'.
* If JOBU = 'A', U contains the M-by-M unitary matrix U;
* if JOBU = 'S', U contains the first min(m,n) columns of U
* (the left singular vectors, stored columnwise);
* if JOBU = 'N' or 'O', U is not referenced.
*
* @param[in] LDU
* The leading dimension of the array U. LDU >= 1; if
* JOBU = 'S' or 'A', LDU >= M.
*
* @param[out] VT
* If JOBVT = 'A', VT contains the N-by-N unitary matrix
* V**H;
* if JOBVT = 'S', VT contains the first min(m,n) rows of
* V**H (the right singular vectors, stored rowwise);
* if JOBVT = 'N' or 'O', VT is not referenced.
*
* @param[in] LDVT
* The leading dimension of the array VT. LDVT >= 1; if
* JOBVT = 'A', LDVT >= N; if JOBVT = 'S', LDVT >= min(M,N).
*
*******************************************************************************
*
* @return
* \return PLASMA_SUCCESS successful exit
*
*******************************************************************************
*
* @sa PLASMA_zgesdd
* @sa PLASMA_zgesdd_Tile_Async
* @sa PLASMA_cgesdd_Tile
* @sa PLASMA_dgesdd_Tile
* @sa PLASMA_sgesdd_Tile
*
******************************************************************************/
int PLASMA_zgesdd_Tile(PLASMA_enum jobu, PLASMA_enum jobvt,
PLASMA_desc *A,
double *S,
PLASMA_desc *T,
PLASMA_Complex64_t *U, int LDU,
PLASMA_Complex64_t *VT, int LDVT)
{
plasma_context_t *plasma;
PLASMA_sequence *sequence = NULL;
PLASMA_request request = PLASMA_REQUEST_INITIALIZER;
int status;
plasma = plasma_context_self();
if (plasma == NULL) {
plasma_fatal_error("PLASMA_zgesdd_Tile", "PLASMA not initialized");
return PLASMA_ERR_NOT_INITIALIZED;
}
plasma_sequence_create(plasma, &sequence);
PLASMA_zgesdd_Tile_Async(jobu, jobvt, A, S, T, U, LDU, VT, LDVT, sequence, &request);
plasma_dynamic_sync();
status = sequence->status;
plasma_sequence_destroy(plasma, sequence);
return status;
}
/***************************************************************************//**
*
* @ingroup PLASMA_Complex64_t_Tile_Async
*
* PLASMA_zgesdd_Tile_Async - computes the singular value decomposition (SVD) of a complex
* M-by-N matrix A, optionally computing the left and/or right singular
* vectors.
* Non-blocking equivalent of PLASMA_zgesdd_Tile().
* May return before the computation is finished.
* Allows for pipelining of operations at runtime.
*
*******************************************************************************
*
* @param[in] sequence
* Identifies the sequence of function calls that this call belongs to
* (for completion checks and exception handling purposes).
*
* @param[out] request
* Identifies this function call (for exception handling purposes).
*
*******************************************************************************
*
* @sa PLASMA_zgesdd
* @sa PLASMA_zgesdd_Tile
* @sa PLASMA_cgesdd_Tile_Async
* @sa PLASMA_dgesdd_Tile_Async
* @sa PLASMA_sgesdd_Tile_Async
*
******************************************************************************/
int PLASMA_zgesdd_Tile_Async(PLASMA_enum jobu, PLASMA_enum jobvt,
PLASMA_desc *A,
double *S,
PLASMA_desc *T,
PLASMA_Complex64_t *U, int LDU,
PLASMA_Complex64_t *VT, int LDVT,
PLASMA_sequence *sequence, PLASMA_request *request)
{
PLASMA_desc descA;
PLASMA_desc descT;
PLASMA_desc descU, descVT;
PLASMA_Complex64_t *AB;
double *E;
int M;
int N;
int MINMN;
int NB;
int LDAB;
int i;
int status;
plasma_context_t *plasma;
plasma = plasma_context_self();
if (plasma == NULL) {
plasma_fatal_error("PLASMA_zgesdd_Tile_Async", "PLASMA not initialized");
return PLASMA_ERR_NOT_INITIALIZED;
}
if (sequence == NULL) {
plasma_fatal_error("PLASMA_zgesdd_Tile_Async", "NULL sequence");
return PLASMA_ERR_UNALLOCATED;
}
if (request == NULL) {
plasma_fatal_error("PLASMA_zgesdd_Tile_Async", "NULL request");
return PLASMA_ERR_UNALLOCATED;
}
/* Check sequence status */
if (sequence->status == PLASMA_SUCCESS)
request->status = PLASMA_SUCCESS;
else
return plasma_request_fail(sequence, request, PLASMA_ERR_SEQUENCE_FLUSHED);
/* Check descriptors for correctness */
if (plasma_desc_check(A) != PLASMA_SUCCESS) {
plasma_error("PLASMA_zgesdd_Tile_Async", "invalid first descriptor");
return plasma_request_fail(sequence, request, PLASMA_ERR_ILLEGAL_VALUE);
} else {
descA = *A;
}
if (plasma_desc_check(T) != PLASMA_SUCCESS) {
plasma_error("PLASMA_zgesdd_Tile_Async", "invalid fourth descriptor");
return plasma_request_fail(sequence, request, PLASMA_ERR_ILLEGAL_VALUE);
} else {
descT = *T;
}
/* Check input arguments */
if (jobu != PlasmaNoVec && jobu != PlasmaVec) {
plasma_error("PLASMA_zgesdd_Tile_Async", "illegal value of jobu");
return PLASMA_ERR_NOT_SUPPORTED;
}
if (jobvt != PlasmaNoVec && jobvt != PlasmaVec) {
plasma_error("PLASMA_zgesdd_Tile_Async", "illegal value of jobvt");
return PLASMA_ERR_NOT_SUPPORTED;
}
if (jobvt != jobu) {
plasma_error("PLASMA_zgesdd_Tile_Async", "in this version: jobu should be equal jobvt");
return PLASMA_ERR_NOT_SUPPORTED;
}
if (descA.nb != descA.mb) {
plasma_error("PLASMA_zgesdd_Tile_Async", "only square tiles supported");
return plasma_request_fail(sequence, request, PLASMA_ERR_ILLEGAL_VALUE);
}
#if defined(ENABLE_TIMER)
PLASMA_Double_t timelpk=0.0,timeaplQ2=0.0, timeT=0.0;
PLASMA_Double_t timeB=0.0,timeblg=0.0,timeaplQ1=0.0,timeconv1=0.0,timeconv2=0.0,timeall=0.0;
timeall = PLASMA_Wtime();
#endif
PLASMA_enum uplo = descA.m >= descA.n ? PlasmaUpper : PlasmaLower;
M = descA.m;
N = descA.n;
MINMN = min(M,N);
NB = min(descA.mb,MINMN);
LDAB = 3*NB+1;
/*=======================================
* case M<NB or N<NB call lapack
*=======================================*/
if( ( M<= NB) || ( N <=NB ) ){
/* convert the tile descA to lapack A */
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
AB = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, M*N, PlasmaComplexDouble);
if (AB == NULL) {
plasma_error("PLASMA_zgesvd_Tile_Async", "plasma_shared_alloc(AB-0-) failed");
plasma_shared_free(plasma, AB);
return PLASMA_ERR_OUT_OF_RESOURCES;
}
plasma_zooptile2lap( descA, AB, NB, NB, M, N, sequence, request);
} else {
AB = descA.mat;
plasma_ziptile2lap( descA, AB, NB, NB, M, N, sequence, request);
}
plasma_dynamic_sync();
/*=======================================
* calling LAPACK ZGESVD
*=======================================*/
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timelpk = PLASMA_Wtime();
#endif
plasma_setlapack_multithreads(plasma->world_size);
/* call SVD solver using lapack routine */
PLASMA_enum jobz = jobu == PlasmaVec ? PlasmaAllVec : PlasmaNoVec;
status = LAPACKE_zgesdd(LAPACK_COL_MAJOR, lapack_const(jobz),
M, N, AB, M, S, U, LDU, VT, LDVT);
if(status != 0){
plasma_error("PLASMA_zgesvd","ZGESVD");
}
sequence->status = status;
plasma_setlapack_sequential(plasma);
#if defined(ENABLE_TIMER)
timelpk = PLASMA_Wtime()-timelpk;
printf(" Finish Eigensolver-lpkonly timing= %lf threads %d\n" ,timelpk, plasma->world_size);
#endif
/*=======================================
* END of calling SVD solver
*=======================================*/
/* convert the lapack to the tile descA */
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
//plasma_zooplap2tile_noalloc( descA, AB, NB, NB, M, N, 0, 0, M, N, sequence, request);
plasma_parallel_call_5( plasma_pzlapack_to_tile,
PLASMA_Complex64_t*, AB,
int, M,
PLASMA_desc, descA,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
plasma_dynamic_sync();
free(AB);
} else {
plasma_ziplap2tile( descA, AB, NB, NB, M, N, 0, 0, M, N,
sequence, request);
}
plasma_dynamic_sync();
return PLASMA_SUCCESS;
}
/*=======================================
* END OF case M<NB or N<NB
*=======================================*/
/*
* Allocate workspace for band storage of the band matrix A
* AB looks like:
* __________________________________
* NB | zero |
* ----------------------------------
* NB+1 | band A |
* ----------------------------------
* NB |_______________zero_______________|
*
* */
AB = (PLASMA_Complex64_t *)plasma_shared_alloc(plasma, LDAB*MINMN, PlasmaComplexDouble);
memset( AB, 0, LDAB * MINMN * sizeof(PLASMA_Complex64_t) );
if (AB == NULL) {
plasma_error("PLASMA_zgesdd_Tile_Async", "plasma_shared_alloc(AB) failed");
plasma_shared_free(plasma, AB);
return PLASMA_ERR_OUT_OF_RESOURCES;
}
E = (double *)plasma_shared_alloc(plasma, MINMN, PlasmaRealDouble);
if (E == NULL) {
plasma_error("PLASMA_zgesdd_Tile_Async", "plasma_shared_alloc(E) failed");
plasma_shared_free(plasma, E);
return PLASMA_ERR_OUT_OF_RESOURCES;
}
/*=======================================
* calling Reduction from DENSE to BAND
* then convert matrix to band form
*=======================================*/
//plasma_dynamic_sync();
#if defined(ENABLE_TIMER)
timeB = PLASMA_Wtime();
#endif
/*
* Reduction to BAND bidiagonal form
* May be further optimized using the algo described in Trefethen
*/
/* if (plasma->householder == PLASMA_FLAT_HOUSEHOLDER) { */
plasma_dynamic_call_4(plasma_pzgebrd_ge2gb,
PLASMA_desc, descA,
PLASMA_desc, descT,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
/* } */
/* else { */
/* plasma_dynamic_call_4(plasma_pzgebrd_ge2gb_rh, */
/* PLASMA_desc, descA, */
/* PLASMA_desc, descT, */
/* PLASMA_sequence*, sequence, */
/* PLASMA_request*, request); */
/* } */
//plasma_dynamic_sync();
plasma_dynamic_call_6( plasma_pzgbcpy_t2bl,
PLASMA_enum, descA.m >= descA.n ? PlasmaUpper : PlasmaLower,
PLASMA_desc, descA,
PLASMA_Complex64_t*, &(AB[NB]),
int, LDAB,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
plasma_dynamic_sync();
status = sequence->status;
if (status != PLASMA_SUCCESS) {
plasma_error("PLASMA_zgesdd","pzgebrd_ge2gb+pzcopy");
return status;
}
#if defined(ENABLE_TIMER)
timeB = PLASMA_Wtime()-timeB;
printf("\n Finish Band red timing= %lf \n",timeB);
#endif
/*=======================================
* END of calling Reduction to BAND
*=======================================*/
/*=======================================
* calling Reduction from BAND to bidiag
*=======================================*/
PLASMA_Complex64_t *VQ2 = NULL;
PLASMA_Complex64_t *VP2 = NULL;
PLASMA_Complex64_t *TAUQ2 = NULL;
PLASMA_Complex64_t *TAUP2 = NULL;
PLASMA_Complex64_t *TQ2 = NULL;
PLASMA_Complex64_t *TP2 = NULL;
int Vblksiz, blkcnt, LDT, LDV;
int WANTZ = 0;
/* compute fraction of singular vectors */
/* for future use when a portion of the eigenvectors are requested */
int ME = M;
int NE = N;
int MINMNE = MINMN;
/*
int fraction = 100;
if((fraction<100)&&(fraction>0)) {
MINMNE = plasma_ceildiv(fraction*MINMN,100);
ME = MINMNE;
NE = MINMNE;
}
*/
if( jobu == PlasmaNoVec )
WANTZ=0;
else
WANTZ=2;
/* Vblksiz correspond to the blocking used when applying V2 to the matrix U
* it is similar to IB in LAPACK ZUNMQR.
* blkcnt is the number of diamond or tile of Vs */
/* Note that in case PlamaVec requested, the V2 and T2 are stored by the
* bulgechasing function in a special format:
* for V2s: it store the V2(LDV,Vblksiz) of each diamond in a tile storage meaning
* that V2_1 is stored then V2_2,..., V2_blkcnt.
* blkcnt is the number of diamond.
* */
Vblksiz = min(NB,48);
LDT = Vblksiz;
/* data for U */
if( jobu == PlasmaVec ) {
findVTsiz(MINMN, NB, Vblksiz, &blkcnt, &LDV);
TAUQ2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, blkcnt*Vblksiz, PlasmaComplexDouble);
VQ2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, LDV*blkcnt*Vblksiz, PlasmaComplexDouble);
TQ2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, LDT*blkcnt*Vblksiz, PlasmaComplexDouble);
if ( (TAUQ2 == NULL) || (VQ2 == NULL) || (TQ2 == NULL) ) {
plasma_error("PLASMA_zgesdd", "plasma_shared_alloc() failed");
plasma_shared_free(plasma, TAUQ2);
plasma_shared_free(plasma, VQ2);
plasma_shared_free(plasma, TQ2);
return PLASMA_ERR_OUT_OF_RESOURCES;
}
memset(TAUQ2, 0, blkcnt*Vblksiz*sizeof(PLASMA_Complex64_t));
memset(VQ2, 0, LDV*blkcnt*Vblksiz*sizeof(PLASMA_Complex64_t));
memset(TQ2, 0, LDT*blkcnt*Vblksiz*sizeof(PLASMA_Complex64_t));
}
else {
TAUQ2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, 2*MINMN, PlasmaComplexDouble);
VQ2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, 2*MINMN, PlasmaComplexDouble);
if ( (TAUQ2 == NULL) || (VQ2 == NULL) ) {
plasma_error("PLASMA_zgesdd", "plasma_shared_alloc() failed");
plasma_shared_free(plasma, TAUQ2);
plasma_shared_free(plasma, VQ2);
return PLASMA_ERR_OUT_OF_RESOURCES;
}
memset(TAUQ2, 0, 2*MINMN*sizeof(PLASMA_Complex64_t));
memset(VQ2, 0, 2*MINMN*sizeof(PLASMA_Complex64_t));
}
/* data for VT */
if( jobvt == PlasmaVec ) {
findVTsiz(MINMN, NB, Vblksiz, &blkcnt, &LDV);
TAUP2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, blkcnt*Vblksiz, PlasmaComplexDouble);
VP2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, LDV*blkcnt*Vblksiz, PlasmaComplexDouble);
TP2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, LDT*blkcnt*Vblksiz, PlasmaComplexDouble);
if ( (TAUP2 == NULL) || (VP2 == NULL) || (TP2 == NULL) ) {
plasma_error("PLASMA_zgesdd", "plasma_shared_alloc() failed");
plasma_shared_free(plasma, TAUP2);
plasma_shared_free(plasma, VP2);
plasma_shared_free(plasma, TP2);
return PLASMA_ERR_OUT_OF_RESOURCES;
}
memset(TAUP2, 0, blkcnt*Vblksiz*sizeof(PLASMA_Complex64_t));
memset(VP2, 0, LDV*blkcnt*Vblksiz*sizeof(PLASMA_Complex64_t));
memset(TP2, 0, LDT*blkcnt*Vblksiz*sizeof(PLASMA_Complex64_t));
}
else {
TAUP2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, 2*MINMN, PlasmaComplexDouble);
VP2 = (PLASMA_Complex64_t *) plasma_shared_alloc(plasma, 2*MINMN, PlasmaComplexDouble);
if ( (TAUP2 == NULL) || (VP2 == NULL) ) {
plasma_error("PLASMA_zgesdd", "plasma_shared_alloc() failed");
plasma_shared_free(plasma, TAUQ2);
plasma_shared_free(plasma, VQ2);
return PLASMA_ERR_OUT_OF_RESOURCES;
}
memset(TAUP2, 0, 2*MINMN*sizeof(PLASMA_Complex64_t));
memset(VP2, 0, 2*MINMN*sizeof(PLASMA_Complex64_t));
}
/*=======================================
* calling bulge chasing
*=======================================*/
#if defined(ENABLE_TIMER)
timeblg = PLASMA_Wtime();
#endif
plasma_parallel_call_16(plasma_pzgebrd_gb2bd_v1,
PLASMA_enum, uplo,
int, MINMN,
int, NB,
int, Vblksiz,
PLASMA_Complex64_t*, AB,
int, LDAB,
PLASMA_Complex64_t*, VQ2,
PLASMA_Complex64_t*, TAUQ2,
PLASMA_Complex64_t*, VP2,
PLASMA_Complex64_t*, TAUP2,
double*, S,
double*, E,
int, WANTZ,
int, WANTZ,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
/* WARNING: If plasma_pzgebrd_gb2bd is implemented through a dynamic call, don't
* forget to synchronize */
plasma_dynamic_sync();
#if defined(ENABLE_TIMER)
timeblg = PLASMA_Wtime()-timeblg;
printf(" Finish Bulge timing= %lf \n" ,timeblg);
#endif
/*=======================================
* END of calling bulge chasing
*=======================================*/
/*=======================================
* calling SVD solver
*=======================================*/
plasma_setlapack_multithreads(plasma->world_size);
/* call SVD solver using lapack routine for our resulting bidiag [S E] */
/* call eigensolver using lapack routine for our resulting tridiag [D E] */
if((jobu == PlasmaNoVec)&&(jobvt == PlasmaNoVec)){
#if defined(ENABLE_TIMER)
timelpk = PLASMA_Wtime();
#endif
status = LAPACKE_dbdsdc(LAPACK_COL_MAJOR, lapack_const(uplo), lapack_const(PlasmaNoVec),
MINMN, S, E, NULL, LDU, NULL, LDVT, NULL, NULL);
#if defined(ENABLE_TIMER)
timelpk = PLASMA_Wtime()-timelpk;
#endif
} else {
// set U and VT to zero
memset(VT, 0, N*LDVT*sizeof(PLASMA_Complex64_t));
memset(U, 0, M*LDU*sizeof(PLASMA_Complex64_t));
/* Initialize U(N+1:M,N+1:M) and VT(M+1:N,M+1:N) to Identity */
for(i=N; i<M; i++){
U[i+i*LDU] = 1.0;
}
for(i=M; i<N; i++){
VT[i+i*LDVT] = 1.0;
}
#if defined COMPLEX
int j;
double *RU = NULL;
double *RVT = NULL;
RU = (double *) plasma_shared_alloc(plasma, MINMN*MINMN, PlasmaRealDouble);
RVT = (double *) plasma_shared_alloc(plasma, MINMN*MINMN, PlasmaRealDouble);
#if defined(ENABLE_TIMER)
timelpk = PLASMA_Wtime();
#endif
status = LAPACKE_dbdsdc(LAPACK_COL_MAJOR, lapack_const(uplo), lapack_const(PlasmaIvec),
MINMN, S, E, RU, MINMN, RVT, MINMN, NULL, NULL);
#if defined(ENABLE_TIMER)
timelpk = PLASMA_Wtime()-timelpk;
#endif
// copy the real U and VT matrix to the complex
//LAPACKE_zlacp2(LAPACK_COL_MAJOR, lapack_const(uplo), MINMN, MINMN, RU, MINMN, U, LDU );
//LAPACKE_zlacp2(LAPACK_COL_MAJOR, lapack_const(uplo), MINMN, MINMN, RVT, MINMN, VT, LDVT );
for(j=0; j<MINMN; j++){
for(i=0; i<MINMN; i++){
U[i+j*LDU] = (PLASMA_Complex64_t) RU[i+j*MINMN];
}
}
for(j=0; j<MINMN; j++){
for(i=0; i<MINMN; i++){
VT[i+j*LDVT] = (PLASMA_Complex64_t) RVT[i+j*MINMN];
}
}
plasma_shared_free(plasma, RU);
plasma_shared_free(plasma, RVT);
#else
#if defined(ENABLE_TIMER)
timelpk = PLASMA_Wtime();
#endif
status = LAPACKE_dbdsdc(LAPACK_COL_MAJOR, lapack_const(uplo), lapack_const(PlasmaIvec),
MINMN, S, E, U, LDU, VT, LDVT, NULL, NULL);
#if defined(ENABLE_TIMER)
timelpk = PLASMA_Wtime()-timelpk;
#endif
#endif
}
if(status != 0){
plasma_error("PLASMA_zbdedc","ZBDEDC");
/*return status;*/
}
sequence->status = status;
plasma_setlapack_sequential(plasma);
#if defined(ENABLE_TIMER)
int fraction = (MINMNE*100)/N;
printf(" Finish Eigensolver timing= %lf WANTZ %d threads %d fraction %d MINMNE %d \n" ,timelpk, WANTZ, plasma->world_size, fraction, MINMNE);
#endif
/*=======================================
* END of calling SVD solver
*=======================================*/
/*=======================================
* generate U from the bulge
*=======================================*/
if (jobu == PlasmaVec){
#if defined(ENABLE_TIMER)
timeT = PLASMA_Wtime();
#endif
/* compute T2 */
plasma_static_call_8(plasma_pzlarft_blgtrd,
int, MINMN,
int, NB,
int, Vblksiz,
PLASMA_Complex64_t*, VQ2,
PLASMA_Complex64_t*, TQ2,
PLASMA_Complex64_t*, TAUQ2,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeT = PLASMA_Wtime()-timeT;
printf(" Finish compute TU2 timing= %lf \n" ,timeT);
timeaplQ2 = PLASMA_Wtime();
#endif
/* apply Q2 from Left */
plasma_static_call_14(plasma_pzunmqr_blgtrd,
PLASMA_enum, PlasmaLeft,
PLASMA_enum, PlasmaNoTrans,
int, MINMN,
int, NB,
int, MINMNE,
int, Vblksiz,
int, WANTZ,
PLASMA_Complex64_t*, VQ2,
PLASMA_Complex64_t*, TQ2,
PLASMA_Complex64_t*, TAUQ2,
PLASMA_Complex64_t*, U,
int, LDU,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeaplQ2 = PLASMA_Wtime()-timeaplQ2;
printf(" Finish compute U2 timing= %lf \n" ,timeaplQ2);
#endif
/*=======================================
* apply Q1 from the reduction to band
*=======================================*/
/* CASE NB>N, Q1 doesn't need to be applied, only bulge chasing has been done */
if( NB < N ){
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeconv1 = PLASMA_Wtime();
#endif
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
plasma_zooplap2tile( descU, U, NB, NB, LDU, ME, 0, 0, M, ME, sequence, request, plasma_desc_mat_free(&(descU)) );
} else {
plasma_ziplap2tile( descU, U, NB, NB, LDU, ME, 0, 0, M, ME, sequence, request);
}
#if defined(ENABLE_TIMER)
timeconv1 = PLASMA_Wtime()-timeconv1;
timeaplQ1 = PLASMA_Wtime();
#endif
/* Accumulate the transformations from the first stage */
if(M<N){
plasma_dynamic_call_7(plasma_pzunmqr,
PLASMA_enum, PlasmaLeft,
PLASMA_enum, PlasmaNoTrans,
PLASMA_desc, plasma_desc_submatrix(descA, descA.mb, 0, descA.m-descA.mb, descA.n-descA.nb),
PLASMA_desc, plasma_desc_submatrix(descU, descU.mb, 0, descU.m-descU.mb, descU.n),
PLASMA_desc, plasma_desc_submatrix(descT, descT.mb, 0, descT.m-descT.mb, descT.n-descT.nb),
PLASMA_sequence*, sequence,
PLASMA_request*, request);
}
else {
plasma_dynamic_call_7(plasma_pzunmqr,
PLASMA_enum, PlasmaLeft,
PLASMA_enum, PlasmaNoTrans,
PLASMA_desc, descA,
PLASMA_desc, descU,
PLASMA_desc, descT,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
}
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeaplQ1 = PLASMA_Wtime()-timeaplQ1;
printf(" Finish compute U1 timing= %lf \n" ,timeaplQ1);
timeconv2 = PLASMA_Wtime();
#endif
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
plasma_zooptile2lap( descU, U, NB, NB, LDU, ME, sequence, request );
plasma_dynamic_sync();
plasma_desc_mat_free(&descU);
} else {
plasma_ziptile2lap( descU, U, NB, NB, LDU, ME, sequence, request );
plasma_dynamic_sync();
}
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeconv2 = PLASMA_Wtime()-timeconv2;
printf(" Finish convert U timing= %lf \n" ,timeconv1+timeconv2);
#endif
} /* END of ( NB < N ) */
}
/*=======================================
* END of calling computing U
*=======================================*/
/*=======================================
* generate VT from the bulge
*=======================================*/
if (jobvt == PlasmaVec){
#if defined(ENABLE_TIMER)
timeT = PLASMA_Wtime();
#endif
/* compute T2 */
plasma_static_call_8(plasma_pzlarft_blgtrd,
int, MINMN,
int, NB,
int, Vblksiz,
PLASMA_Complex64_t*, VP2,
PLASMA_Complex64_t*, TP2,
PLASMA_Complex64_t*, TAUP2,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeT = PLASMA_Wtime()-timeT;
printf(" Finish compute TV2 timing= %lf \n" ,timeT);
timeaplQ2 = PLASMA_Wtime();
#endif
/* apply Q2 from Left */
plasma_static_call_14(plasma_pzunmqr_blgtrd,
PLASMA_enum, PlasmaRight,
PLASMA_enum, PlasmaConjTrans,
int, MINMN,
int, NB,
int, MINMNE,
int, Vblksiz,
int, WANTZ,
PLASMA_Complex64_t*, VP2,
PLASMA_Complex64_t*, TP2,
PLASMA_Complex64_t*, TAUP2,
PLASMA_Complex64_t*, VT,
int, LDVT,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeaplQ2 = PLASMA_Wtime()-timeaplQ2;
printf(" Finish compute V2 timing= %lf \n" ,timeaplQ2);
#endif
/*=======================================
* apply Q1 from the reduction to band
*=======================================*/
/* CASE NB>N, Q1 doesn't need to be applied, only bulge chasing has been done */
if( NB < N ){
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeconv1 = PLASMA_Wtime();
#endif
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
plasma_zooplap2tile( descVT, VT, NB, NB, LDVT, N, 0, 0, NE, N, sequence, request, plasma_desc_mat_free(&(descVT)) );
} else {
plasma_ziplap2tile( descVT, VT, NB, NB, LDVT, N, 0, 0, NE, N, sequence, request);
}
#if defined(ENABLE_TIMER)
timeconv1 = PLASMA_Wtime()-timeconv1;
timeaplQ1 = PLASMA_Wtime();
#endif
/* Accumulate the transformations from the first stage */
if(M<N){
plasma_dynamic_call_7(plasma_pzunmlq,
PLASMA_enum, PlasmaRight,
PLASMA_enum, PlasmaNoTrans,
PLASMA_desc, descA,
PLASMA_desc, descVT,
PLASMA_desc, descT,
PLASMA_sequence*, sequence,
PLASMA_request*, request);
}
else {
plasma_dynamic_call_7(plasma_pzunmlq,
PLASMA_enum, PlasmaRight,
PLASMA_enum, PlasmaNoTrans,
PLASMA_desc, plasma_desc_submatrix(descA, 0, descA.nb, descA.m-descA.mb, descA.n-descA.nb),
PLASMA_desc, plasma_desc_submatrix(descVT,0, descVT.nb, descVT.m, descVT.n-descVT.nb),
PLASMA_desc, plasma_desc_submatrix(descT, 0, descT.nb, descT.m-descT.mb, descT.n-descT.nb),
PLASMA_sequence*, sequence,
PLASMA_request*, request);
}
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeaplQ1 = PLASMA_Wtime()-timeaplQ1;
printf(" Finish compute V1 timing= %lf \n" ,timeaplQ1);
timeconv2 = PLASMA_Wtime();
#endif
if ( PLASMA_TRANSLATION == PLASMA_OUTOFPLACE ) {
plasma_zooptile2lap( descVT, VT, NB, NB, LDVT, N, sequence, request );
plasma_dynamic_sync();
plasma_desc_mat_free(&descVT);
} else {
plasma_ziptile2lap( descVT, VT, NB, NB, LDVT, N, sequence, request );
plasma_dynamic_sync();
}
#if defined(ENABLE_TIMER)
plasma_dynamic_sync();
timeconv2 = PLASMA_Wtime()-timeconv2;
printf(" Finish convert VT timing= %lf \n" ,timeconv1+timeconv2);
#endif
} /* END of ( NB < N ) */
}
/*=======================================
* END of calling computing VT
*=======================================*/
#if defined(ENABLE_TIMER)
timeall = PLASMA_Wtime()-timeall;
printf(" Finish full eigenproblem threads %d N %d fraction %d MINMNE %d timeall= %lf \n", plasma->world_size, MINMN, fraction, MINMNE, timeall);
#endif
if( jobu == PlasmaVec )
plasma_shared_free(plasma, TQ2);
if( jobvt == PlasmaVec )
plasma_shared_free(plasma, TP2);
plasma_shared_free(plasma, VQ2);
plasma_shared_free(plasma, TAUQ2);
plasma_shared_free(plasma, VP2);
plasma_shared_free(plasma, TAUP2);
plasma_shared_free(plasma, E);
plasma_shared_free(plasma, AB);
return PLASMA_SUCCESS;
}
| {
"alphanum_fraction": 0.533150328,
"avg_line_length": 40.5911237016,
"ext": "c",
"hexsha": "961896f96786924736a4674eb520b4a490576196",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zhuangsc/Plasma-ompss1",
"max_forks_repo_path": "compute/zgesdd.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zhuangsc/Plasma-ompss1",
"max_issues_repo_path": "compute/zgesdd.c",
"max_line_length": 153,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zhuangsc/Plasma-ompss1",
"max_stars_repo_path": "compute/zgesdd.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11476,
"size": 42986
} |
/*
* Module that implements in c a Bayesian network trained with probabilistic
* backpropagation (PBP).
*
* Author: Jose Miguel Hernandez Lobato
* Date: 10 March 2015
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <malloc.h>
#include <cblas.h>
#include "network.h"
#include "pnorm.h"
/* Prototipes of private functions */
void refine_prior(NETWORK *network);
void do_ADF_update(NETWORK * network, double *x, double y);
double randn(double mu, double sigma);
/**
* Generates a sample from a Gaussian distribution
* @param mu Mean of the Gaussian.
* @param sigma Standard deviation of the Gaussian
*
*/
double randn(double mu, double sigma) {
double U1, U2, W, mult;
static double X1, X2;
static int call = 0;
if (call == 1)
{
call = !call;
return (mu + sigma * (double) X2);
}
do
{
U1 = -1 + ((double) rand () / RAND_MAX) * 2;
U2 = -1 + ((double) rand () / RAND_MAX) * 2;
W = pow (U1, 2) + pow (U2, 2);
}
while (W >= 1 || W == 0);
mult = sqrt ((-2 * log (W)) / W);
X1 = U1 * mult;
X2 = U2 * mult;
call = !call;
return (mu + sigma * (double) X1);
}
/**
* Constructor for a network.
*
* @param size_hidden_layers The size of each hidden layer.
* @param n_hidden_layers The number of hidden layers.
* @param d The input dimensionality.
* @param random_noise Random noise for the initialization of the
* posterior means.
*
*/
NETWORK *init_network(int *size_hidden_layers, int n_hidden_layers, int d,double *random_noise) {
NETWORK *ret;
int n, i, j, k;
/* We save memory for the structure */
ret = malloc(sizeof(NETWORK));
/* We initialize the number of hidden layers */
ret->n_hidden_layers = n_hidden_layers;
/* We refine the prior on the noise variance and on the prior variance */
ret->a_noise = 2.0 * 3;
ret->b_noise = 2.0 * 3;
ret->a_prior = 2.0 * 3;
ret->b_prior = 2.0 * 3;
/* We save memory for the array with the number of neurons per layer,
* the activation type, the scaling of the activation per layer,
and he starting position for the different arrays */
ret->neurons_per_layer = malloc(sizeof(int) * (n_hidden_layers + 3));
ret->linear = malloc(sizeof(int) * (n_hidden_layers + 3));
ret->scaling_a = malloc(sizeof(double) * (n_hidden_layers + 3));
ret->start_w = malloc(sizeof(int) * (n_hidden_layers + 3));
ret->start_z = malloc(sizeof(int) * (n_hidden_layers + 3));
ret->start_a = malloc(sizeof(int) * (n_hidden_layers + 3));
/* We initialize the number of neurons per layer, the activation type and
* compute the size of the auxiliary variables */
/* The input layer */
ret->start_w[ 0 ] = -1;
ret->start_z[ 0 ] = 0;
ret->start_a[ 0 ] = 0;
ret->neurons_per_layer[ 0 ] = d;
ret->linear[ 0 ] = 0;
ret->scaling_a[ 0 ] = 1.0;
ret->size_w = 0;
ret->size_a = d;
ret->size_z = d + 1;
/* The hidden layers */
for (i = 1 ; i < n_hidden_layers + 1 ; i ++) {
ret->start_w[ i ] = ret->size_w;
ret->start_z[ i ] = ret->size_z;
ret->start_a[ i ] = ret->size_a;
ret->neurons_per_layer[ i ] = size_hidden_layers[ i - 1 ];
ret->linear[ i ] = 0;
ret->scaling_a[ i ] = 1.0 / (ret->neurons_per_layer[ i - 1 ] + 1);
ret->size_w += (ret->neurons_per_layer[ i - 1 ] + 1) * ret->neurons_per_layer[ i ];
ret->size_a += ret->neurons_per_layer[ i ];
ret->size_z += ret->neurons_per_layer[ i ] + 1;
}
/* The output layer */
ret->start_w[ i ] = ret->size_w;
ret->start_z[ i ] = ret->size_z;
ret->start_a[ i ] = ret->size_a;
ret->neurons_per_layer[ i ] = 1;
ret->linear[ i ] = 1;
ret->scaling_a[ i ] = 1.0 / (ret->neurons_per_layer[ i - 1 ] + 1);
ret->size_w += (ret->neurons_per_layer[ i - 1 ] + 1) * ret->neurons_per_layer[ i ];
ret->size_a += ret->neurons_per_layer[ i ];
ret->size_z += ret->neurons_per_layer[ i ] + 1;
/* The fake output layer */
i++;
ret->start_w[ i ] = ret->size_w;
ret->start_z[ i ] = ret->size_z;
ret->start_a[ i ] = ret->size_a;
ret->neurons_per_layer[ i ] = 1;
ret->linear[ i ] = 1;
ret->scaling_a[ i ] = 1.0;
ret->size_w += (ret->neurons_per_layer[ i - 1 ] + 1) * ret->neurons_per_layer[ i ];
ret->size_a += ret->neurons_per_layer[ i ];
ret->size_z += ret->neurons_per_layer[ i ] + 1;
/* We save memory for the auxiliary variables */
ret->sample_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->m_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->m_w_new = (double *) malloc(sizeof(double) * ret->size_w);
ret->m_w_squared = (double *) malloc(sizeof(double) * ret->size_w);
ret->v_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->v_w_new = (double *) malloc(sizeof(double) * ret->size_w);
ret->m_z = (double *) malloc(sizeof(double) * ret->size_z);
ret->m_z_scaled = (double *) malloc(sizeof(double) * ret->size_z);
ret->m_z_squared = (double *) malloc(sizeof(double) * ret->size_z);
ret->v_z = (double *) malloc(sizeof(double) * ret->size_z);
ret->v_z_scaled = (double *) malloc(sizeof(double) * ret->size_z);
ret->m_a = (double *) malloc(sizeof(double) * ret->size_a);
ret->v_a = (double *) malloc(sizeof(double) * ret->size_a);
ret->alpha = (double *) malloc(sizeof(double) * ret->size_a);
ret->gamma = (double *) malloc(sizeof(double) * ret->size_a);
ret->delta_m = (double *) malloc(sizeof(double) * ret->size_z);
ret->delta_v = (double *) malloc(sizeof(double) * ret->size_z);
ret->dm_z_d_m_a = (double *) malloc(sizeof(double) * ret->size_z);
ret->dv_z_d_m_a = (double *) malloc(sizeof(double) * ret->size_z);
ret->dm_z_d_v_a = (double *) malloc(sizeof(double) * ret->size_z);
ret->dv_z_d_v_a = (double *) malloc(sizeof(double) * ret->size_z);
ret->dm_a_d_m_a = (double *) malloc(sizeof(double) * ret->size_w);
ret->dv_a_d_m_a = (double *) malloc(sizeof(double) * ret->size_w);
ret->dm_a_d_v_a = (double *) malloc(sizeof(double) * ret->size_w);
ret->dv_a_d_v_a = (double *) malloc(sizeof(double) * ret->size_w);
ret->dm_a_d_m_z = (double *) malloc(sizeof(double) * ret->size_w);
ret->dv_a_d_m_z = (double *) malloc(sizeof(double) * ret->size_w);
ret->dm_a_d_v_z = (double *) malloc(sizeof(double) * ret->size_w);
ret->dv_a_d_v_z = (double *) malloc(sizeof(double) * ret->size_w);
ret->dm_a_d_m_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->dv_a_d_m_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->dm_a_d_v_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->dv_a_d_v_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->grad_m_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->grad_v_w = (double *) malloc(sizeof(double) * ret->size_w);
ret->m_w_hat_nat = (double *) malloc(sizeof(double) * ret->size_w);
ret->v_w_hat_nat = (double *) malloc(sizeof(double) * ret->size_w);
ret->a_w_hat_nat = (double *) malloc(sizeof(double) * ret->size_w);
ret->b_w_hat_nat = (double *) malloc(sizeof(double) * ret->size_w);
ret->m_w_old = (double *) malloc(sizeof(double) * ret->size_w);
ret->v_w_old = (double *) malloc(sizeof(double) * ret->size_w);
/* We initialize the posterior approximation */
k = 0;
for (i = 1 ; i < n_hidden_layers + 3 ; i ++) {
n = (ret->neurons_per_layer[ i - 1 ] + 1) * ret->neurons_per_layer[ i ];
for (j = 0 ; j < n ; j++) {
ret->m_w[ k ] = 1.0 / sqrt(ret->neurons_per_layer[ i - 1 ] + 1) * random_noise[ k ];
ret->v_w[ k ] = ret->b_prior / (ret->a_prior - 1);
ret->m_w_hat_nat[ k ] = 0;
ret->v_w_hat_nat[ k ] = (ret->a_prior - 1) / ret->b_prior;
ret->a_w_hat_nat[ k ] = 0;
ret->b_w_hat_nat[ k ] = 0;
k++;
}
}
/* We initialize the weights of the fake ouput layer */
ret->m_w[ ret->start_w[ n_hidden_layers + 2 ] ] = 1.0;
ret->m_w[ ret->start_w[ n_hidden_layers + 2 ] + 1 ] = 0.0;
ret->v_w[ ret->start_w[ n_hidden_layers + 2 ] ] = 0.0;
ret->v_w[ ret->start_w[ n_hidden_layers + 2 ] + 1 ] = 0.0;
return ret;
}
/**
* Constructor for a network.
*
* @param network Pointer to the network to destroy.
*
*/
void destroy_network(NETWORK *n) {
free(n->neurons_per_layer);
free(n->linear);
free(n->scaling_a);
free(n->start_w);
free(n->start_a);
free(n->start_z);
free(n->sample_w);
free(n->m_w);
free(n->m_w_new);
free(n->m_w_squared);
free(n->v_w);
free(n->v_w_new);
free(n->m_z);
free(n->m_z_squared);
free(n->m_z_scaled);
free(n->v_z);
free(n->m_a);
free(n->v_a);
free(n->alpha);
free(n->gamma);
free(n->delta_m);
free(n->delta_v);
free(n->dm_z_d_m_a);
free(n->dv_z_d_m_a);
free(n->dm_z_d_v_a);
free(n->dv_z_d_v_a);
free(n->dm_a_d_m_a);
free(n->dv_a_d_m_a);
free(n->dm_a_d_v_a);
free(n->dv_a_d_v_a);
free(n->dm_a_d_m_z);
free(n->dv_a_d_m_z);
free(n->dm_a_d_v_z);
free(n->dv_a_d_v_z);
free(n->dm_a_d_m_w);
free(n->dv_a_d_m_w);
free(n->dm_a_d_v_w);
free(n->dv_a_d_v_w);
free(n->grad_m_w);
free(n->grad_v_w);
free(n->m_w_hat_nat);
free(n->v_w_hat_nat);
free(n->a_w_hat_nat);
free(n->b_w_hat_nat);
free(n->m_w_old);
free(n->v_w_old);
return;
}
/**
* Deterministic forward propagation of the data.
*
*/
void deterministc_forward_PBP(NETWORK *n, int index_layer) {
int i;
double sqrt_aux;
/* Auxiliary pointers */
double * __restrict__ sample_w;
double * __restrict__ m_z;
double * __restrict__ m_z_previous_layer;
double * __restrict__ m_a;
/* Auxiliary variables */
double scaling_a;
int n_neurons;
int input_size;
int linear;
/* We initialize the pointers */
sample_w = n->sample_w + n->start_w[ index_layer ];
m_z = n->m_z + n->start_z[ index_layer ];
m_z_previous_layer = n->m_z + n->start_z[ index_layer - 1 ];
m_a = n->m_a + n->start_a[ index_layer ];
/* We update the number of neurons, input size, type of activation and scaling constant */
n_neurons = n->neurons_per_layer[ index_layer ];
input_size = n->neurons_per_layer[ index_layer - 1 ] + 1;
linear = n->linear[ index_layer ];
scaling_a = n->scaling_a[ index_layer ];
/* We compute the scaled activation mean: sqrt_aux * sample_w x m_z */
sqrt_aux = sqrt(scaling_a);
cblas_dgemv(CblasRowMajor, CblasNoTrans, n_neurons, input_size, sqrt_aux, sample_w, input_size, m_z_previous_layer, 1, 0.0, m_a, 1);
/* We apply the non-linearity or compute a linear activation function */
if (linear) {
for (i = 0 ; i < n_neurons ; i++) {
m_z[ i ] = m_a[ i ];
}
} else {
for (i = 0 ; i < n_neurons ; i++) {
m_z[ i ] = (m_a[ i ] > 0) ? m_a[ i ] : 0;
}
}
/* We add the bias if we are not in the two last layers */
if (index_layer < n->n_hidden_layers + 1) {
m_z[ n_neurons ] = 1.0;
}
}
/**
* Forward propagation of probabilities.
*
*/
void forward_PBP(NETWORK *n, int index_layer) {
int i, limit;
double a, a2, p, g, sqrt_aux;
/* Auxiliary pointers */
double * __restrict__ m_w;
double * __restrict__ m_w_squared;
double * __restrict__ v_w;
double * __restrict__ m_z;
double * __restrict__ v_z;
double * __restrict__ m_a;
double * __restrict__ v_a;
double * __restrict__ m_z_previous_layer;
double * __restrict__ m_z_previous_layer_squared;
double * __restrict__ v_z_previous_layer;
double * __restrict__ alpha;
double * __restrict__ gamma;
/* Auxiliary variables */
double scaling_a;
int n_neurons;
int input_size;
int linear;
/* We initialize the pointers */
m_w = n->m_w + n->start_w[ index_layer ];
m_w_squared = n->m_w_squared + n->start_w[ index_layer ];
v_w = n->v_w + n->start_w[ index_layer ];
m_z = n->m_z + n->start_z[ index_layer ];
v_z = n->v_z + n->start_z[ index_layer ];
m_a = n->m_a + n->start_a[ index_layer ];
v_a = n->v_a + n->start_a[ index_layer ];
m_z_previous_layer = n->m_z + n->start_z[ index_layer - 1 ];
v_z_previous_layer = n->v_z + n->start_z[ index_layer - 1 ];
m_z_previous_layer_squared = n->m_z_squared + n->start_z[ index_layer - 1 ];
alpha = n->alpha + n->start_a[ index_layer ];
gamma = n->gamma + n->start_a[ index_layer ];
/* We update the number of neurons, input size, type of activation and scaling constant */
n_neurons = n->neurons_per_layer[ index_layer ];
input_size = n->neurons_per_layer[ index_layer - 1 ] + 1;
linear = n->linear[ index_layer ];
scaling_a = n->scaling_a[ index_layer ];
/* We compute the m_z_previous_layer_squared and the m_w_squared */
limit = n_neurons * input_size;
for (i = 0 ; i < limit ; i++)
m_w_squared[ i ] = m_w[ i ] * m_w[ i ];
for (i = 0 ; i < input_size ; i++)
m_z_previous_layer_squared[ i ] = m_z_previous_layer[ i ] * m_z_previous_layer[ i ];
/* We compute the scaled activation mean: sqrt_aux * m_w x m_z */
sqrt_aux = sqrt(scaling_a);
cblas_dgemv(CblasRowMajor, CblasNoTrans, n_neurons, input_size, sqrt_aux, m_w, input_size, m_z_previous_layer, 1, 0.0, m_a, 1);
/* We compute the scaled activation variance: (m_w_squared x v_z_previous_layer +
v_w x m_z_previous_layer_squared + v_w x v_z_previous_layer) */
cblas_dgemv(CblasRowMajor, CblasNoTrans, n_neurons, input_size, scaling_a, m_w_squared, input_size, v_z_previous_layer, 1, 0, v_a, 1);
cblas_dgemv(CblasRowMajor, CblasNoTrans, n_neurons, input_size, scaling_a, v_w, input_size, m_z_previous_layer_squared, 1, 1.0, v_a, 1);
cblas_dgemv(CblasRowMajor, CblasNoTrans, n_neurons, input_size, scaling_a, v_w, input_size, v_z_previous_layer, 1, 1.0, v_a, 1);
/* We apply the non-linearity or compute a linear activation function */
if (linear) {
for (i = 0 ; i < n_neurons ; i++) {
m_z[ i ] = m_a[ i ];
v_z[ i ] = v_a[ i ];
}
} else {
for (i = 0 ; i < n_neurons ; i++) {
sqrt_aux = sqrt(v_a[ i ]);
a = m_a[ i ] / sqrt_aux;
a2 = a * a;
p = pnorm(a);
g = (a < -30) ? -a - 1.0 / a + 2.0 / (a * a2) : 0.398942280401432677939946059 * exp(-0.5 * a2) / p;
/* We compute the output mean and variance */
m_z[ i ] = p * (m_a[ i ] + sqrt_aux * g);
v_z[ i ] = m_z[ i ] * (m_a[ i ] + sqrt_aux * g) * (1 - p) + p * v_a[ i ] * (1 - g * g - g * a);
alpha[ i ] = a;
gamma[ i ] = g;
}
}
/* We add the bias if we are not in the two last layers */
if (index_layer < n->n_hidden_layers + 1) {
m_z[ n_neurons ] = 1.0;
v_z[ n_neurons ] = 0.0;
}
}
/**
* Backward computation of gradients.
*
*/
void backward_PBP(NETWORK *n, int index_layer) {
double g, a, da_dm_a, da_dv_a, dg_dm_a, dg_dv_a, d, p;
int i, j, k, limit_1, limit_2;
/* Auxiliary pointers */
double * __restrict__ m_w;
double * __restrict__ m_w_layer_above;
double * __restrict__ v_w_layer_above;
double * __restrict__ m_z;
double * __restrict__ m_z_scaled;
double * __restrict__ m_a;
double * __restrict__ v_a;
double * __restrict__ m_z_layer_below;
double * __restrict__ m_z_layer_below_scaled;
double * __restrict__ v_z_layer_below;
double * __restrict__ v_z_layer_below_scaled;
double * __restrict__ alpha;
double * __restrict__ gamma;
double * __restrict__ delta_m_layer_above;
double * __restrict__ delta_v_layer_above;
double * __restrict__ delta_m;
double * __restrict__ delta_v;
double * __restrict__ dm_z_d_m_a;
double * __restrict__ dv_z_d_m_a;
double * __restrict__ dm_z_d_v_a;
double * __restrict__ dv_z_d_v_a;
double * __restrict__ dm_a_d_m_a;
double * __restrict__ dv_a_d_m_a;
double * __restrict__ dm_a_d_v_a;
double * __restrict__ dv_a_d_v_a;
double * __restrict__ dm_a_d_m_z;
double * __restrict__ dv_a_d_m_z;
double * __restrict__ dm_a_d_v_z;
double * __restrict__ dv_a_d_v_z;
double * __restrict__ dm_a_d_m_w;
double * __restrict__ dv_a_d_m_w;
double * __restrict__ dm_a_d_v_w;
double * __restrict__ dv_a_d_v_w;
double * __restrict__ grad_m_w;
double * __restrict__ grad_v_w;
/* Auxiliary variables */
double scaling_a, scaling_a_layer_above, sqrt_aux, sqrt_v_a;
double *p_aux_1, *p_aux_2, *p_aux_3, *p_aux_4;
double *p_aux_1_2, *p_aux_2_2, *p_aux_3_2, *p_aux_4_2;
int n_neurons;
int linear;
/* We initialize the auxiliary pointers */
m_w = n->m_w + n->start_w[ index_layer ];
m_w_layer_above = n->m_w + n->start_w[ index_layer + 1 ];
v_w_layer_above = n->v_w + n->start_w[ index_layer + 1 ];
m_z = n->m_z + n->start_z[ index_layer ];
m_z_scaled = n->m_z_scaled + n->start_z[ index_layer ];
m_a = n->m_a + n->start_a[ index_layer ];
v_a = n->v_a + n->start_a[ index_layer ];
m_z_layer_below = n->m_z + n->start_z[ index_layer - 1 ];
v_z_layer_below = n->v_z + n->start_z[ index_layer - 1 ];
m_z_layer_below_scaled = n->m_z_scaled + n->start_z[ index_layer - 1 ];
v_z_layer_below_scaled = n->v_z_scaled + n->start_z[ index_layer - 1 ];
alpha = n->alpha + n->start_a[ index_layer ];
gamma = n->gamma + n->start_a[ index_layer ];
delta_m_layer_above = n->delta_m + n->start_z[ index_layer + 1 ];
delta_v_layer_above = n->delta_v + n->start_z[ index_layer + 1 ];
delta_m = n->delta_m + n->start_z[ index_layer ];
delta_v = n->delta_v + n->start_z[ index_layer ];
dm_z_d_m_a = n->dm_z_d_m_a + n->start_z[ index_layer ];
dv_z_d_m_a = n->dv_z_d_m_a + n->start_z[ index_layer ];
dm_z_d_v_a = n->dm_z_d_v_a + n->start_z[ index_layer ];
dv_z_d_v_a = n->dv_z_d_v_a + n->start_z[ index_layer ];
dm_a_d_m_a = n->dm_a_d_m_a + n->start_w[ index_layer ];
dv_a_d_m_a = n->dv_a_d_m_a + n->start_w[ index_layer ];
dm_a_d_v_a = n->dm_a_d_v_a + n->start_w[ index_layer ];
dv_a_d_v_a = n->dv_a_d_v_a + n->start_w[ index_layer ];
dm_a_d_m_z = n->dm_a_d_m_z + n->start_w[ index_layer ];
dv_a_d_m_z = n->dv_a_d_m_z + n->start_w[ index_layer ];
dm_a_d_v_z = n->dm_a_d_v_z + n->start_w[ index_layer ];
dv_a_d_v_z = n->dv_a_d_v_z + n->start_w[ index_layer ];
dm_a_d_m_w = n->dm_a_d_m_w + n->start_w[ index_layer ];
dv_a_d_m_w = n->dv_a_d_m_w + n->start_w[ index_layer ];
dm_a_d_v_w = n->dm_a_d_v_w + n->start_w[ index_layer ];
dv_a_d_v_w = n->dv_a_d_v_w + n->start_w[ index_layer ];
grad_m_w = n->grad_m_w + n->start_w[ index_layer ];
grad_v_w = n->grad_v_w + n->start_w[ index_layer ];
/* We update the number of neurons, input size, type of activation and scaling constant */
n_neurons = n->neurons_per_layer[ index_layer ];
linear = n->linear[ index_layer ];
scaling_a = n->scaling_a[ index_layer ];
scaling_a_layer_above = n->scaling_a[ index_layer + 1 ];
/* We compute the gradient of the non-linear activations with respect to the activations */
if (linear) {
for (i = 0 ; i < n_neurons ; i++) {
dm_z_d_m_a[ i ] = 1.0;
dm_z_d_v_a[ i ] = 0.0;
dv_z_d_m_a[ i ] = 0.0;
dv_z_d_v_a[ i ] = 1.0;
}
} else {
for (i = 0 ; i < n_neurons ; i++) {
g = gamma[ i ];
a = alpha[ i ];
da_dm_a = 1.0 / sqrt(v_a[ i ]);
da_dv_a = m_a[ i ] / (2 * v_a[ i ]) * da_dm_a;
if (a < -30) {
g = -a - 1.0 / a + 2.0 / (a * a * a);
dg_dm_a = -da_dm_a + 1.0 / (a * a) * da_dm_a - 6.0 / (a * a * a * a) * da_dm_a;
dg_dv_a = -da_dv_a + 1.0 / (a * a) * da_dv_a - 6.0 / (a * a * a * a) * da_dv_a;
} else {
dg_dm_a = -(g * a + g * g) * da_dm_a;
dg_dv_a = -(g * a + g * g) * da_dv_a;
}
d = 0.398942280401432677939946059 * exp(-0.5 * a * a);
p = pnorm(a);
sqrt_v_a = sqrt(v_a[ i ]);
dm_z_d_m_a[ i ] = da_dm_a * d * (m_a[ i ] + sqrt_v_a * g) + p * (1 + sqrt_v_a * dg_dm_a);
dm_z_d_v_a[ i ] = da_dv_a * d * (m_a[ i ] + sqrt_v_a * g) + p * (g / (2 * sqrt_v_a) + sqrt_v_a * dg_dv_a);
dv_z_d_m_a[ i ] = dm_z_d_m_a[ i ] * (m_a[ i ] + sqrt_v_a * g) * (1 - p) + m_z[ i ] * ((1 + sqrt_v_a * dg_dm_a) * (1 - p) -
(m_a[ i ] + sqrt_v_a * g) * d * da_dm_a) + d * da_dm_a * v_a[ i ] * (1 - g * g - g * a) - p * v_a[ i ] *
(2 * g * dg_dm_a + dg_dm_a * a + g * da_dm_a);
dv_z_d_v_a[ i ] = dm_z_d_v_a[ i ] * (m_a[ i ] + sqrt_v_a * g) * (1 - p) + m_z[ i ] * ((0.5 / sqrt_v_a * g + dg_dv_a * sqrt_v_a) * (1 - p) -
(m_a[ i ]+ sqrt_v_a * g) * d * da_dv_a) + d * da_dv_a * v_a[ i ] * (1 - g * g - g * a) + p * ((1 - g * g - g * a) + v_a[ i ] *
(-2 * g * dg_dv_a - dg_dv_a * a - g * da_dv_a));
}
}
/* We scale m_z */
limit_1 = n_neurons + 1;
for (i = 0 ; i < limit_1 ; i++) {
m_z_scaled[ i ] = m_z[ i ] * scaling_a_layer_above;
}
/* We initialize the rows of dv_a_dm_z to m_z_scaled */
limit_1 = n->neurons_per_layer[ index_layer + 1 ];
limit_2 = n_neurons + 1;
for (i = 0 ; i < limit_1 ; i++) {
p_aux_1 = dv_a_d_m_z + i * limit_2;
for (j = 0 ; j < limit_2 ; j++) {
p_aux_1[ j ] = m_z_scaled[ j ];
}
}
/* We compute the gradient of the activation of the layer above with respect to the non-linear activations in this layer */
sqrt_aux = sqrt(scaling_a_layer_above);
limit_1 = n->neurons_per_layer[ index_layer + 1 ] * (n_neurons + 1);
for (i = 0 ; i < limit_1 ; i++) {
dm_a_d_m_z[ i ] = m_w_layer_above[ i ] * sqrt_aux;
dm_a_d_v_z[ i ] = 0;
dv_a_d_m_z[ i ] = dv_a_d_m_z[ i ] * 2 * v_w_layer_above[ i ];
dv_a_d_v_z[ i ] = (m_w_layer_above[ i ] * m_w_layer_above[ i ] + v_w_layer_above[ i ]) * scaling_a_layer_above;
}
/* We scale the activatons from the layer below */
sqrt_aux = sqrt(scaling_a);
limit_1 = n->neurons_per_layer[ index_layer - 1 ] + 1;
for (i = 0 ; i < limit_1 ; i++) {
m_z_layer_below_scaled[ i ] = m_z_layer_below[ i ] * sqrt_aux;
v_z_layer_below_scaled[ i ] = v_z_layer_below[ i ] * scaling_a;
}
/* We initialize dm_a_dm_w, dv_a_dm_w and dv_a_dv_w */
limit_1 = n_neurons;
limit_2 = n->neurons_per_layer[ index_layer - 1 ] + 1;
for (i = 0 ; i < limit_1 ; i++) {
p_aux_1 = dm_a_d_m_w + i * limit_2;
p_aux_2 = dv_a_d_m_w + i * limit_2;
p_aux_3 = dv_a_d_v_w + i * limit_2;
for (j = 0 ; j < limit_2 ; j++) {
p_aux_1[ j ] = m_z_layer_below_scaled[ j ];
p_aux_2[ j ] = v_z_layer_below_scaled[ j ];
p_aux_3[ j ] = (m_z_layer_below_scaled[ j ] * m_z_layer_below_scaled[ j ] + v_z_layer_below_scaled[ j ]);
}
}
limit_1 = n_neurons * (n->neurons_per_layer[ index_layer - 1 ] + 1);
for (i = 0 ; i < limit_1 ; i++) {
dm_a_d_v_w[ i ] = 0;
dv_a_d_m_w[ i ] = 2 * dv_a_d_m_w[ i ] * m_w[ i ];
}
/* We compute the gradient of the activations of the top layer with respect to the activations of the current layer */
limit_1 = n->neurons_per_layer[ index_layer + 1 ];
limit_2 = n_neurons + 1;
k = 0;
for (i = 0 ; i < limit_1 ; i++) {
p_aux_1 = dm_a_d_m_a + i * limit_2;
p_aux_2 = dv_a_d_m_a + i * limit_2;
p_aux_3 = dm_a_d_v_a + i * limit_2;
p_aux_4 = dv_a_d_v_a + i * limit_2;
p_aux_1_2 = dm_a_d_m_z + i * limit_2;
p_aux_2_2 = dm_a_d_v_z + i * limit_2;
p_aux_3_2 = dv_a_d_m_z + i * limit_2;
p_aux_4_2 = dv_a_d_v_z + i * limit_2;
for (j = 0 ; j < limit_2 - 1 ; j++) {
p_aux_1[ j ] = p_aux_1_2[ j ] * dm_z_d_m_a[ j ] + p_aux_2_2[ j ] * dv_z_d_m_a[ j ];
p_aux_2[ j ] = p_aux_3_2[ j ] * dm_z_d_m_a[ j ] + p_aux_4_2[ j ] * dv_z_d_m_a[ j ];
p_aux_3[ j ] = p_aux_1_2[ j ] * dm_z_d_v_a[ j ] + p_aux_2_2[ j ] * dv_z_d_v_a[ j ];
p_aux_4[ j ] = p_aux_3_2[ j ] * dm_z_d_v_a[ j ] + p_aux_4_2[ j ] * dv_z_d_v_a[ j ];
}
}
/* We compute the deltas */
limit_1 = n->neurons_per_layer[ index_layer + 1 ];
cblas_dgemv(CblasRowMajor, CblasTrans, limit_1, n_neurons + 1, 1.0, dm_a_d_m_a, n_neurons + 1, delta_m_layer_above, 1, 0.0, delta_m, 1);
cblas_dgemv(CblasRowMajor, CblasTrans, limit_1, n_neurons + 1, 1.0, dv_a_d_m_a, n_neurons + 1, delta_v_layer_above, 1, 1.0, delta_m, 1);
cblas_dgemv(CblasRowMajor, CblasTrans, limit_1, n_neurons + 1, 1.0, dm_a_d_v_a, n_neurons + 1, delta_m_layer_above, 1, 0.0, delta_v, 1);
cblas_dgemv(CblasRowMajor, CblasTrans, limit_1, n_neurons + 1, 1.0, dv_a_d_v_a, n_neurons + 1, delta_v_layer_above, 1, 1.0, delta_v, 1);
/* We compute the gradients */
limit_1 = n_neurons;
limit_2 = n->neurons_per_layer[ index_layer - 1 ] + 1;
k = 0;
for (i = 0 ; i < limit_1 ; i++) {
for (j = 0 ; j < limit_2 ; j++) {
grad_m_w[ k ] = delta_m[ i ] * dm_a_d_m_w[ k ] + delta_v[ i ] * dv_a_d_m_w[ k ];
grad_v_w[ k ] = delta_m[ i ] * dm_a_d_v_w[ k ] + delta_v[ i ] * dv_a_d_v_w[ k ];
k++;
}
}
}
/**
* Function that performs an ADF update.
*
* @param network Pointer to the network.
* @param x Pointer to the input features.
* @param y Pointer to the target.
*
*/
void do_ADF_update(NETWORK * n, double *x, double y) {
int i, limit_1;
double * __restrict__ m_z;
double * __restrict__ v_z;
double * __restrict__ delta_m;
double * __restrict__ delta_v;
double * __restrict__ m_w;
double * __restrict__ v_w;
double * __restrict__ grad_m_w;
double * __restrict__ grad_v_w;
double m, v, v1, v2, logZ, logZ1, logZ2, d_logZ_d_m, d_logZ_d_v, a_new, b_new, m_aux, v_aux;
/* We initialize the non-linear activations of the input layer with the data */
limit_1 = n->start_a[ 1 ];
m_z = n->m_z;
v_z = n->v_z;
for (i = 0 ; i < limit_1 ; i++) {
m_z[ i ] = x[ i ];
v_z[ i ] = 0.0;
}
m_z[ i ] = 1.0;
v_z[ i ] = 0.0;
/* We do a forward pass */
limit_1 = n->n_hidden_layers + 2;
for (i = 1 ; i < limit_1 ; i++)
forward_PBP(n, i);
/* We obtain logZ, logZ1 and logZ2 and the updates for a and b */
m_z = n->m_z + n->start_z[ n->n_hidden_layers + 1 ];
v_z = n->v_z + n->start_z[ n->n_hidden_layers + 1 ];
m = m_z[ 0 ];
v = v_z[ 0 ] + n->b_noise / (n->a_noise - 1);
v1 = v_z[ 0 ] + n->b_noise / (n->a_noise - 0);
v2 = v_z[ 0 ] + n->b_noise / (n->a_noise + 1);
logZ = -0.5 * (log(v) + (m - y) * (m - y) / v);
logZ1 = -0.5 * (log(v1) + (m - y) * (m - y) / v1);
logZ2 = -0.5 * (log(v2) + (m - y) * (m - y) / v2);
a_new = 1.0 / (exp(logZ2 - 2 * logZ1 + logZ) * (n->a_noise + 1.0) / n->a_noise - 1.0);
b_new = 1.0 / (exp(logZ2 - logZ1) * (n->a_noise + 1) / n->b_noise - exp(logZ1 - logZ) * n->a_noise / n->b_noise);
/* We initialize the deltas for the output layer */
d_logZ_d_m = -(m - y) / v;
d_logZ_d_v = -0.5 / v + 0.5 * (m - y) * (m - y) / (v * v);
delta_m = n->delta_m + n->start_z[ n->n_hidden_layers + 2 ];
delta_v = n->delta_v + n->start_z[ n->n_hidden_layers + 2 ];
delta_m[ 0 ] = d_logZ_d_m;
delta_v[ 0 ] = d_logZ_d_v;
/* We do a backward pass */
limit_1 = n->n_hidden_layers + 1;
for (i = limit_1 ; i >= 1 ; i--)
backward_PBP(n, i);
/* We update the mean and variance parameters, except those in the fake output layer */
m_w = n->m_w;
v_w = n->v_w;
grad_m_w = n->grad_m_w;
grad_v_w = n->grad_v_w;
limit_1 = n->size_w - 2;
for (i = 0 ; i < limit_1 ; i++) {
v_aux = v_w[ i ] - v_w[ i ] * v_w[ i ] * (grad_m_w[ i ] * grad_m_w[ i ] - 2 * grad_v_w[ i ]);
m_aux = m_w[ i ] + v_w[ i ] * grad_m_w[ i ];
if (v_aux > 1e-100 && m_aux != NAN && v_aux != NAN) {
m_w[ i ] = m_aux;
v_w[ i ] = v_aux;
}
}
/* We update the noise variables */
n->b_noise = b_new;
n->a_noise = a_new;
}
/**
* Function that refines the approximate factor for the prior.
*
* @param network Pointer to the network.
*
*/
void refine_prior(NETWORK *n) {
int i;
double v_w_nat, m_w_nat, v_w_cav_nat, m_w_cav_nat, v_w_cav, m_w_cav,
a_w_nat, b_w_nat, a_w_cav_nat, b_w_cav_nat, a_w_cav, b_w_cav,
v, v1, v2, logZ, logZ1, logZ2, d_logZ_d_m_w_cav, d_logZ_d_v_w_cav,
m_w_new, v_w_new, a_w_new, b_w_new, v_w_new_nat, m_w_new_nat,
a_w_new_nat, b_w_new_nat;
/* We iterate over the layers refining the prior */
for (i = 0 ; i < n->size_w - 2 ; i++) {
v_w_nat = 1.0 / n->v_w[ i ];
m_w_nat = n->m_w[ i ] / n->v_w[ i ];
v_w_cav_nat = v_w_nat - n->v_w_hat_nat[ i ];
m_w_cav_nat = m_w_nat - n->m_w_hat_nat[ i ];
v_w_cav = 1.0 / v_w_cav_nat;
m_w_cav = m_w_cav_nat / v_w_cav_nat;
a_w_nat = n->a_prior - 1;
b_w_nat = -n->b_prior;
a_w_cav_nat = a_w_nat - n->a_w_hat_nat[ i ];
b_w_cav_nat = b_w_nat - n->b_w_hat_nat[ i ];
a_w_cav = a_w_cav_nat + 1;
b_w_cav = -b_w_cav_nat;
if (v_w_cav > 0 && b_w_cav > 0 && a_w_cav > 1 && v_w_cav < 1e6) {
v = v_w_cav + b_w_cav / (a_w_cav - 1);
v1 = v_w_cav + b_w_cav / a_w_cav;
v2 = v_w_cav + b_w_cav / (a_w_cav + 1);
logZ = -0.5 * log(v) - 0.5 * m_w_cav * m_w_cav / v;
logZ1 = -0.5 * log(v1) - 0.5 * m_w_cav * m_w_cav / v1;
logZ2 = -0.5 * log(v2) - 0.5 * m_w_cav * m_w_cav / v2;
d_logZ_d_m_w_cav = -m_w_cav / v;
d_logZ_d_v_w_cav = -0.5 / v + 0.5 * m_w_cav * m_w_cav / (v * v);
m_w_new = m_w_cav + v_w_cav * d_logZ_d_m_w_cav;
v_w_new = v_w_cav - v_w_cav * v_w_cav * (d_logZ_d_m_w_cav * d_logZ_d_m_w_cav - 2 * d_logZ_d_v_w_cav) ;
a_w_new = 1.0 / (exp(logZ2 - 2 * logZ1 + logZ) * (a_w_cav + 1) / a_w_cav - 1.0);
b_w_new = 1.0 / (exp(logZ2 - logZ1) * (a_w_cav + 1) / (b_w_cav) - exp(logZ1 - logZ) * a_w_cav / b_w_cav);
v_w_new_nat = 1.0 / v_w_new;
m_w_new_nat = m_w_new / v_w_new;
a_w_new_nat = a_w_new - 1;
b_w_new_nat = -b_w_new;
n->m_w_hat_nat[ i ] = m_w_new_nat - m_w_cav_nat;
n->v_w_hat_nat[ i ] = v_w_new_nat - v_w_cav_nat;
n->a_w_hat_nat[ i ] = a_w_new_nat - a_w_cav_nat;
n->b_w_hat_nat[ i ] = b_w_new_nat - b_w_cav_nat;
n->m_w[ i ] = m_w_new;
n->v_w[ i ] = v_w_new;
n->a_prior = a_w_new;
n->b_prior = b_w_new;
}
}
}
/**
* Function that performs one learning epoch.
*
* @param network Pointer to the network.
* @param x Pointer to the input feature matrix.
* @param y Pointer to the target vector.
* @param n_datapoints Number of data points in the training set.
* @param d Dimensionality of the training data.
* @param permutation A random permuation of the input data.
*
*/
NETWORK *one_learning_epoch(NETWORK *n, double *x, double *y, int n_datapoints, int d, int *permutation) {
int i, index;
/* We do one ADF upte for each datapoint */
for (i = 0 ; i < n_datapoints ; i++) {
index = permutation[ i ] * d;
do_ADF_update(n, x + index, y[ permutation[ i ] ]);
if (i % 1000 == 0) {
printf(".");
fflush(stdout);
}
}
printf("\n");
fflush(stdout);
/* We refine the prior */
refine_prior(n);
/* We are done */
return n;
}
/**
* Function that predicts deterministically.
*
* @param network Pointer to the network.
* @param x_test Pointer to the input feature matrix.
* @param y_test Pointer to store the predictions.
* @param n_datapoints Number of data points in the test set.
* @param d Dimensionality of the test data.
*
*/
NETWORK *predict_deterministic(NETWORK *n, double *x_test, double *y_test, int n_datapoints, int d) {
int i, j, index, limit_1;
double *m_z;
for (i = 0 ; i < n_datapoints ; i++) {
/* We initialize the non-linear activations of the input layer with the data */
limit_1 = n->start_a[ 1 ];
m_z = n->m_z;
for (j = 0 ; j < limit_1 ; j++) {
index = i * d + j;
m_z[ j ] = x_test[ index ];
}
m_z[ j ] = 1.0;
/* We do a forward pass */
limit_1 = n->n_hidden_layers + 2;
for (j = 1 ; j < limit_1 ; j++)
deterministc_forward_PBP(n, j);
/* We store the results */
m_z = n->m_z + n->start_z[ n->n_hidden_layers + 1 ];
y_test[ i ] = m_z[ 0 ];
}
/* We are done */
return n;
}
/**
* Function that predicts.
*
* @param network Pointer to the network.
* @param x_test Pointer to the input feature matrix.
* @param m_test Pointer to store the predictive mean.
* @param v_test Pointer to store the predictive variance.
* @param v_noise Pointer to store the noise variance.
* @param n_datapoints Number of data points in the test set.
* @param d Dimensionality of the test data.
*
*/
NETWORK *predict(NETWORK *n, double *x_test, double *m_test, double *v_test, double *v_noise, int n_datapoints, int d) {
int i, j, index, limit_1;
double *m_z, *v_z;
for (i = 0 ; i < n_datapoints ; i++) {
/* We initialize the non-linear activations of the input layer with the data */
limit_1 = n->start_a[ 1 ];
m_z = n->m_z;
v_z = n->v_z;
for (j = 0 ; j < limit_1 ; j++) {
index = i * d + j;
m_z[ j ] = x_test[ index ];
v_z[ j ] = 0.0;
}
m_z[ j ] = 1.0;
v_z[ j ] = 0.0;
/* We do a forward pass */
limit_1 = n->n_hidden_layers + 2;
for (j = 1 ; j < limit_1 ; j++)
forward_PBP(n, j);
/* We store the results */
m_z = n->m_z + n->start_z[ n->n_hidden_layers + 1 ];
v_z = n->v_z + n->start_z[ n->n_hidden_layers + 1 ];
m_test[ i ] = m_z[ 0 ];
v_test[ i ] = v_z[ 0 ];
}
/* We store the noise value */
*v_noise = n->b_noise / (n->a_noise - 1);
/* We are done */
return n;
}
/* Function that returns the parameters of the network */
void get_params(NETWORK *n, double *sample_w_out, double *m_w_out, double *v_w_out, double *m_w_hat_nat_out, double *v_w_hat_nat_out,
double *a_w_hat_nat_out, double *b_w_hat_nat_out, double *a_noise_out, double *b_noise_out, double *a_prior_out,
double *b_prior_out, int *neurons_per_layer_out) {
int i, limit_1;
/* We copy the parameters */
limit_1 = n->size_w - 2;
for (i = 0 ; i < limit_1 ; i++) {
sample_w_out[ i ] = n->sample_w[ i ];
m_w_out[ i ] = n->m_w[ i ];
v_w_out[ i ] = n->v_w[ i ];
m_w_hat_nat_out[ i ] = n->m_w_hat_nat[ i ];
v_w_hat_nat_out[ i ] = n->v_w_hat_nat[ i ];
a_w_hat_nat_out[ i ] = n->a_w_hat_nat[ i ];
b_w_hat_nat_out[ i ] = n->b_w_hat_nat[ i ];
}
*a_noise_out = n->a_noise;
*b_noise_out = n->b_noise;
*a_prior_out = n->a_prior;
*b_prior_out = n->b_prior;
limit_1 = n->n_hidden_layers + 2;
for (i = 0 ; i < limit_1 ; i++) {
neurons_per_layer_out[ i ] = n->neurons_per_layer[ i ];
}
}
/* Function that returns the sizes of the parameters of the network */
void get_size_params(NETWORK *n, int *size_weihts, int *n_layers) {
*size_weihts = n->size_w - 2;
*n_layers = n->n_hidden_layers + 2;
}
/* Function that sets the parameters of the network */
void set_params(NETWORK *n, double *sample_w_in, double *m_w_in, double *v_w_in, double *m_w_hat_nat_in, double *v_w_hat_nat_in,
double *a_w_hat_nat_in, double *b_w_hat_nat_in, double a_noise_in, double b_noise_in, double a_prior_in, double b_prior_in) {
int i, limit_1;
/* We copy the parameters */
limit_1 = n->size_w - 2;
for (i = 0 ; i < limit_1 ; i++) {
n->sample_w[ i ] = sample_w_in[ i ];
n->m_w[ i ] = m_w_in[ i ];
n->v_w[ i ] = v_w_in[ i ];
n->m_w_hat_nat[ i ] = m_w_hat_nat_in[ i ];
n->v_w_hat_nat[ i ] = v_w_hat_nat_in[ i ];
n->a_w_hat_nat[ i ] = a_w_hat_nat_in[ i ];
n->b_w_hat_nat[ i ] = b_w_hat_nat_in[ i ];
}
n->a_noise = a_noise_in;
n->b_noise = b_noise_in;
n->a_prior = a_prior_in;
n->b_prior = b_prior_in;
}
| {
"alphanum_fraction": 0.5787829833,
"avg_line_length": 34.2936288089,
"ext": "c",
"hexsha": "395db3833ad261af1335d397543c447c28515838",
"lang": "C",
"max_forks_count": 74,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T11:25:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-25T16:17:38.000Z",
"max_forks_repo_head_hexsha": "56c9ca818f88fd11e4c38585eefaceb3c28e2184",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "DoktorBotti/Probabilistic-Backpropagation",
"max_forks_repo_path": "c/PBP_net/network.c",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "56c9ca818f88fd11e4c38585eefaceb3c28e2184",
"max_issues_repo_issues_event_max_datetime": "2018-07-09T11:55:07.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T11:55:07.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "DoktorBotti/Probabilistic-Backpropagation",
"max_issues_repo_path": "c/PBP_net/network.c",
"max_line_length": 151,
"max_stars_count": 200,
"max_stars_repo_head_hexsha": "56c9ca818f88fd11e4c38585eefaceb3c28e2184",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "DoktorBotti/Probabilistic-Backpropagation",
"max_stars_repo_path": "c/PBP_net/network.c",
"max_stars_repo_stars_event_max_datetime": "2022-02-16T15:13:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-18T20:23:41.000Z",
"num_tokens": 12422,
"size": 37140
} |
/* histogram/gsl_histogram.h
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
*
* 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.
*/
#ifndef __GSL_HISTOGRAM_H__
#define __GSL_HISTOGRAM_H__
#include <stdlib.h>
#include <stdio.h>
#include <gsl/gsl_types.h>
#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif
__BEGIN_DECLS
typedef struct {
size_t n ;
double * range ;
double * bin ;
} gsl_histogram ;
typedef struct {
size_t n ;
double * range ;
double * sum ;
} gsl_histogram_pdf ;
GSL_EXPORT gsl_histogram * gsl_histogram_alloc (size_t n);
GSL_EXPORT gsl_histogram * gsl_histogram_calloc (size_t n);
GSL_EXPORT gsl_histogram * gsl_histogram_calloc_uniform (const size_t n, const double xmin, const double xmax);
GSL_EXPORT void gsl_histogram_free (gsl_histogram * h);
GSL_EXPORT int gsl_histogram_increment (gsl_histogram * h, double x);
GSL_EXPORT int gsl_histogram_accumulate (gsl_histogram * h, double x, double weight);
GSL_EXPORT int gsl_histogram_find (const gsl_histogram * h,
const double x, size_t * i);
GSL_EXPORT double gsl_histogram_get (const gsl_histogram * h, size_t i);
GSL_EXPORT int gsl_histogram_get_range (const gsl_histogram * h, size_t i,
double * lower, double * upper);
GSL_EXPORT double gsl_histogram_max (const gsl_histogram * h);
GSL_EXPORT double gsl_histogram_min (const gsl_histogram * h);
GSL_EXPORT size_t gsl_histogram_bins (const gsl_histogram * h);
GSL_EXPORT void gsl_histogram_reset (gsl_histogram * h);
GSL_EXPORT gsl_histogram * gsl_histogram_calloc_range(size_t n, double * range);
GSL_EXPORT
int
gsl_histogram_set_ranges (gsl_histogram * h, const double range[], size_t size);
GSL_EXPORT
int
gsl_histogram_set_ranges_uniform (gsl_histogram * h, double xmin, double xmax);
GSL_EXPORT
int
gsl_histogram_memcpy(gsl_histogram * dest, const gsl_histogram * source);
GSL_EXPORT
gsl_histogram *
gsl_histogram_clone(const gsl_histogram * source);
GSL_EXPORT double gsl_histogram_max_val (const gsl_histogram * h);
GSL_EXPORT size_t gsl_histogram_max_bin (const gsl_histogram * h);
GSL_EXPORT double gsl_histogram_min_val (const gsl_histogram * h);
GSL_EXPORT size_t gsl_histogram_min_bin (const gsl_histogram * h);
GSL_EXPORT
int
gsl_histogram_equal_bins_p(const gsl_histogram *h1, const gsl_histogram *h2);
GSL_EXPORT
int
gsl_histogram_add(gsl_histogram *h1, const gsl_histogram *h2);
GSL_EXPORT
int
gsl_histogram_sub(gsl_histogram *h1, const gsl_histogram *h2);
GSL_EXPORT
int
gsl_histogram_mul(gsl_histogram *h1, const gsl_histogram *h2);
GSL_EXPORT
int
gsl_histogram_div(gsl_histogram *h1, const gsl_histogram *h2);
GSL_EXPORT
int
gsl_histogram_scale(gsl_histogram *h, double scale);
GSL_EXPORT
int
gsl_histogram_shift (gsl_histogram * h, double shift);
GSL_EXPORT double gsl_histogram_sigma (const gsl_histogram * h);
GSL_EXPORT double gsl_histogram_mean (const gsl_histogram * h);
GSL_EXPORT double gsl_histogram_sum (const gsl_histogram * h);
GSL_EXPORT int gsl_histogram_fwrite (FILE * stream, const gsl_histogram * h) ;
GSL_EXPORT int gsl_histogram_fread (FILE * stream, gsl_histogram * h);
GSL_EXPORT int gsl_histogram_fprintf (FILE * stream, const gsl_histogram * h,
const char * range_format, const char * bin_format);
GSL_EXPORT int gsl_histogram_fscanf (FILE * stream, gsl_histogram * h);
GSL_EXPORT gsl_histogram_pdf * gsl_histogram_pdf_alloc (const size_t n);
GSL_EXPORT int gsl_histogram_pdf_init (gsl_histogram_pdf * p, const gsl_histogram * h);
GSL_EXPORT void gsl_histogram_pdf_free (gsl_histogram_pdf * p);
GSL_EXPORT double gsl_histogram_pdf_sample (const gsl_histogram_pdf * p, double r);
__END_DECLS
#endif /* __GSL_HISTOGRAM_H__ */
| {
"alphanum_fraction": 0.7684761282,
"avg_line_length": 31.4178082192,
"ext": "h",
"hexsha": "ffb16611586678b80cd067e605199c3a3609ae8b",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f6ed9b75408f7ce6100ed59b7754f745e59be152",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "dynaryu/vaws",
"max_forks_repo_path": "src/core/gsl/include/gsl/gsl_histogram.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f6ed9b75408f7ce6100ed59b7754f745e59be152",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "dynaryu/vaws",
"max_issues_repo_path": "src/core/gsl/include/gsl/gsl_histogram.h",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f6ed9b75408f7ce6100ed59b7754f745e59be152",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "dynaryu/vaws",
"max_stars_repo_path": "src/core/gsl/include/gsl/gsl_histogram.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1129,
"size": 4587
} |
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iterator>
#include <sys/stat.h>
//#define GSL_DLL
//#include <gsl/gsl_cdf.h> //use gaussian p-value function
using namespace std;
void printProgress(double percentage);
| {
"alphanum_fraction": 0.7024539877,
"avg_line_length": 21.7333333333,
"ext": "h",
"hexsha": "88673b90ee1c5865c0a24f65aa26c6e8b3f44898",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f720cdfa989a84dd25855891a8b621390010fd88",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "gui11aume/OnTAD",
"max_forks_repo_path": "src/common.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f720cdfa989a84dd25855891a8b621390010fd88",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "gui11aume/OnTAD",
"max_issues_repo_path": "src/common.h",
"max_line_length": 59,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f720cdfa989a84dd25855891a8b621390010fd88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "gui11aume/OnTAD",
"max_stars_repo_path": "src/common.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 75,
"size": 326
} |
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_odeiv2.h>
typedef struct {
double l, g;
} Params;
int func (double t, const double y[], double f[], void *params) {
Params *p = (Params *) params;
double l = p->l;
double g = p->g;
f[0] = y[1];
f[1] = -(g/l)*y[0];
return GSL_SUCCESS;
}
int jac (double t, const double y[], double *dfdy, double dfdt[],
void *params) {
Params *p = (Params *) params;
double l = p->l;
double g = p->g;
gsl_matrix_view dfdy_mat = gsl_matrix_view_array (dfdy, 2, 2);
gsl_matrix * m = &(dfdy_mat.matrix);
gsl_matrix_set (m, 0, 0, 0.0);
gsl_matrix_set (m, 0, 1, 1.0);
gsl_matrix_set (m, 1, 0, -(g/l));
gsl_matrix_set (m, 1, 1, 0.0);
dfdt[0] = 0.0;
dfdt[1] = 0.0;
return GSL_SUCCESS;
}
int main (void) {
Params params;
params.l = 1.0;
params.g = 9.81;
gsl_odeiv2_system sys = {func, jac, 2, ¶ms};
gsl_odeiv2_driver * d = gsl_odeiv2_driver_alloc_y_new (
&sys, gsl_odeiv2_step_rk8pd, 1e-6, 1e-6, 0.0
);
int i;
double t = 0.0, t1 = 100.0;
double y[2] = { 0.1, 0.0 };
for (i = 1; i <= 1000; i++) {
double ti = i*t1/1000.0;
int status = gsl_odeiv2_driver_apply (d, &t, ti, y);
if (status != GSL_SUCCESS) {
fprintf(stderr, "error, return value=%d\n", status);
break;
}
printf ("%.5le %.5le %.5le\n", t, y[0], y[1]);
}
gsl_odeiv2_driver_free (d);
return EXIT_SUCCESS;
}
| {
"alphanum_fraction": 0.5513307985,
"avg_line_length": 24.65625,
"ext": "c",
"hexsha": "c27a268c8b3af7a1b6b16a16f86e96af5fe2622d",
"lang": "C",
"max_forks_count": 59,
"max_forks_repo_forks_event_max_datetime": "2022-03-21T00:27:22.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-11-26T11:44:51.000Z",
"max_forks_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "Gjacquenot/training-material",
"max_forks_repo_path": "Math/GSL/ODEs/pendulum.c",
"max_issues_count": 56,
"max_issues_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d",
"max_issues_repo_issues_event_max_datetime": "2022-01-03T07:42:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-25T15:04:26.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "Gjacquenot/training-material",
"max_issues_repo_path": "Math/GSL/ODEs/pendulum.c",
"max_line_length": 66,
"max_stars_count": 115,
"max_stars_repo_head_hexsha": "16b29962bf5683f97a1072d961dd9f31e7468b8d",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "Gjacquenot/training-material",
"max_stars_repo_path": "Math/GSL/ODEs/pendulum.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-21T00:27:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-23T13:34:42.000Z",
"num_tokens": 577,
"size": 1578
} |
/* GPC: A library for the solution of General Point Correspondence problems.
Copyright (C) 2006 Andrea Censi (andrea at censi dot org)
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.
*/
#include <math.h>
#include <gsl/gsl_math.h>
#include "gpc.h"
#include "gpc_utils.h"
/* Note that we use static values here so we don't need to evaluate that all the time */
#define M(matrix, rows, col) static gsl_matrix*matrix=0; if(!matrix) matrix = gsl_matrix_alloc(rows,col);
#define MF(matrix) /*gsl_matrix_free(matrix)*/
int gpc_solve(int K, const struct gpc_corr*c,
const double*x0, const double *cov_x0,
double *x_out)
{
M(bigM, 4,4); M(g, 4,1); M(bigM_k,2,4);
M(bigM_k_t,4,2); M(C_k,2,2); M(q_k, 2,1);
M(temp41, 4,1); M(temp22,2,2); M(temp22b,2,2);
M(temp42, 4,2); M(temp44,4,4); M(temp21, 2,1);
M(temp22c, 2,2); M(temp12,1,2);
gsl_matrix_set_zero(bigM);
gsl_matrix_set_zero(g);
gsl_matrix_set_zero(temp42);
double d_bigM[4][4] = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}};
double d_g[4] = {0, 0, 0, 0};
int k;
for(k=0;k<K;k++) {
if(!c[k].valid) continue;
double C00 = c[k].C[0][0];
double C01 = c[k].C[0][1];
double C10 = c[k].C[1][0];
double C11 = c[k].C[1][1];
if(C01 != C10) {
fprintf(stderr, "k=%d; I expect C to be a symmetric matrix.\n", k);
return 0;
}
#if GPC_CHECK_SEMIDEF
double det = C00*C11 - C01*C10;
double trace = C00 + C11;
int is_semidef_pos = (det >= 0) && (trace>0);
if(!is_semidef_pos) {
fprintf(stderr, "k=%d; I expect the matrix to be semidef positive (det>=0 and trace>0), det = %.20f trace= %.10f C = [%.15f,%.15f;%.15f %.15f]\n",
k, det, trace, C00,C01,C10,C11);
return 0;
}
#endif
double qx = c[k].q[0];
double qy = c[k].q[1];
double px = c[k].p[0];
double py = c[k].p[1];
/* [ C00, c01, px C00 + c01 py , c01 px - py C00 ] */
d_bigM[0][0] += C00;
d_bigM[0][1] += C01;
d_bigM[0][2] += +px * C00 + py * C01;
d_bigM[0][3] += -py * C00 + px * C01;
/* [ C10 , C11 , py C11 + px C10 , px C11 - py C10 ] */
d_bigM[1][0] += C10;
d_bigM[1][1] += C11;
d_bigM[1][2] += +px * C10 + py * C11;
d_bigM[1][3] += +px * C11 - py * C10;
/*Col 1 = [ py C10 + px C00 ]
Col 2 = [ py C11 + c01 px ]
Col 3 = [ py (py C11 + px C10) + px (px C00 + c01 py) ]
Col 4 = [ py (px C11 - py C10) + px (c01 px - py C00) ]
*/
d_bigM[2][0] += px * C00 + py * C10;
d_bigM[2][1] += px * C01 + py * C11;
d_bigM[2][2] += (px*px)*(+C00) + (px*py)*(+C10+C01) + (py*py)*(+C11);
d_bigM[2][3] += (px*px)*(+C01) + (px*py)*(-C00+C11) + (py*py)*(-C10);
/*Col 1 = [ px C10 - py C00 ]
Col 2 = [ px C11 - c01 py ]
Col 3 = [ px (py C11 + px C10) - py (px C00 + c01 py) ]
Col 4 = [ px (px C11 - py C10) - py (c01 px - py C00) ]*/
d_bigM[3][0] += -py * C00 + px * C10;
d_bigM[3][1] += -py * C01 + px * C11;
d_bigM[3][2] += (px*px)*(+C10) + (px*py)*(-C00+C11) + (py*py)*(-C01);
d_bigM[3][3] += (px*px)*(+C11) + (px*py)*(-C10-C01) + (py*py)*(+C00);
d_g[0] += C00*qx+C10*qy;
d_g[1] += C01*qx+C11*qy;
d_g[2] += qx * (C00*px+C01*py) + qy * (C10*px+C11*py);
d_g[3] += qx * (C00*(-py)+C01*px) + qy * (C10*(-py)+C11*px);
}
{
unsigned int a,b;
for(a=0;a<4;a++)
*gsl_matrix_ptr(g, a, 0) = -2 * d_g[a];
for(a=0;a<4;a++)
for(b=0;b<4;b++)
gsl_matrix_set(bigM, a, b, 2 * d_bigM[a][b]);
}
M(mA,2,2); gms(mA,0,0, gmg(bigM,0,0)); gms(mA,0,1, gmg(bigM,0,1));
gms(mA,1,0, gmg(bigM,1,0)); gms(mA,1,1, gmg(bigM,1,1));
M(mB,2,2); gms(mB,0,0, gmg(bigM,0,2)); gms(mB,0,1, gmg(bigM,0,3));
gms(mB,1,0, gmg(bigM,1,2)); gms(mB,1,1, gmg(bigM,1,3));
M(mD,2,2); gms(mD,0,0, gmg(bigM,2,2)); gms(mD,0,1, gmg(bigM,2,3));
gms(mD,1,0, gmg(bigM,3,2)); gms(mD,1,1, gmg(bigM,3,3));
M(mS,2,2); M(mSa,2,2);
/* mS = mD - mB.trans * mA.inv * mB;
temp22b = inv(A) */
m_inv(mA, temp22b);
/* temp22c = inv(A) * mB */
m_mult(temp22b, mB, temp22c);
/* temp22 = mB' */
m_trans(mB, temp22);
m_mult(temp22, temp22c, temp22b);
m_scale(-1.0,temp22b);
m_add(mD,temp22b,mS);
/* mSa = mS.inv * mS.det; */
m_inv(mS, mSa);
m_scale(m_det(mS), mSa);
if(TRACE_ALGO) {
m_display("mA",mA);
m_display("mB",mB);
m_display("mD",mD);
m_display("mS",mS);
m_display("mSa",mSa);
}
M(g1,2,1); M(g2,2,1);
M(g1t,1,2); M(g2t,1,2);
M(mAi,2,2); M(mBt,2,2);
gms(g1,0,0,gmg(g,0,0));
gms(g1,1,0,gmg(g,1,0));
gms(g2,0,0,gmg(g,2,0));
gms(g2,1,0,gmg(g,3,0));
m_trans(g1, g1t);
m_trans(g2, g2t);
m_trans(mB, mBt);
m_inv(mA, mAi);
M(m1t,1,2); M(m1,2,1);
M(m2t,1,2); M(m2,2,1);
M(m3t,1,2); M(m3,2,1);
/* m1t = g1t*mAi*mB */
m_mult(g1t,mAi,temp12);
m_mult(temp12,mB,m1t);
m_trans(m1t,m1);
/* m2t = m1t*mSa */
m_mult(m1t,mSa,m2t);
m_trans(m2t,m2);
/* m3t = g2t*mSa */
m_mult(g2t,mSa,m3t);
m_trans(m3t,m3);
double p[3] = {
m_dot(m2t,m2) - 2*m_dot(m2t,m3) + m_dot(m3t,m3),
4*m_dot(m2t,m1) - 8*m_dot(m2t,g2) + 4*m_dot(g2t,m3),
4*m_dot(m1t,m1) - 8*m_dot(m1t,g2) + 4*m_dot(g2t,g2)};
double l[3] = {m_det(mS), 2*gmg(mS,0,0)+2*gmg(mS,1,1), 4};
/* q = p - l^2 */
double q[5] = {p[0]-(l[0]*l[0]), p[1]-(2*l[1]*l[0]),
p[2]-(l[1]*l[1]+2*l[0]*l[2]), -(2*l[2]*l[1]), -(l[2]*l[2])};
if(TRACE_ALGO) {
fprintf(stderr, "p = %f %f %f \n", p[2], p[1], p[0]);
fprintf(stderr, "l = %f %f %f \n", l[2], l[1], l[0]);
fprintf(stderr, "q = %f %f %f %f %f \n", q[4], q[3], q[2], q[1], q[0]);
}
/*
double lambdas[4];
if(!poly_real_roots(5, q, lambdas)) {
fprintf(stderr, "Cannot solve polynomial.\n");
return 0;
}
double lambdas_error[4];
double lambdas_pose[4][3];
for(int i=0;i<4;i++) {
double lambda = lambdas[i];
if(TRACE_ALGO) {
fprintf(stderr, "lambda = %f \n", lambda);
}
M(W,4,4); gsl_matrix_set_zero(W); gms(W,2,2,1.0); gms(W,3,3,1.0);
M(x,4,1);
m_scale(2*lambda, W);
gsl_matrix_add(bigM,W);
m_inv(bigM, temp44);
m_mult(temp44, g, x);
m_scale(-1.0, x);
lambdas_pose[i][0] = gmg(x,0,0);
lambdas_pose[i][1] = gmg(x,1,0);
lambdas_pose[i][2] = atan2(gmg(x,3,0),gmg(x,2,0));
lambdas_error[i] = gpc_total_error(c, K, lambdas_pose[i]);
}
int lowest_error = 0;
for(int i=0;i<4;i++) {
printf("#%d lambda=%lf error=%lf\n",i,lambdas[i],lambdas_error[i]);
if(lambdas_error[i] < lambdas_error[lowest_error])
lowest_error = i;
}
double lr;
poly_greatest_real_root(5,q,&lr);
printf("Choose %d: lambda = %lf bigger real root = %lf \n",lowest_error,lambdas[lowest_error],lr);
x_out[0]=lambdas_pose[lowest_error][0];
x_out[1]=lambdas_pose[lowest_error][1];
x_out[2]=lambdas_pose[lowest_error][2];
*/
double lambda;
if(!poly_greatest_real_root(5, q, &lambda)) return 0;
M(W,4,4); gsl_matrix_set_zero(W); gms(W,2,2,1.0); gms(W,3,3,1.0);
M(x,4,1);
m_scale(2*lambda, W);
gsl_matrix_add(bigM,W);
m_inv(bigM, temp44);
m_mult(temp44, g, x);
m_scale(-1.0, x);
x_out[0] = gmg(x,0,0);
x_out[1] = gmg(x,1,0);
x_out[2] = atan2(gmg(x,3,0),gmg(x,2,0));
if(TRACE_ALGO) {
fprintf(stderr, "x = %f %f %f deg\n", x_out[0], x_out[1],x_out[2]*180/M_PI);
}
MF(mA); MF(mB); MF(mD); MF(mS); MF(mSa);
MF(m1t); MF(m1); MF(m2t); MF(m2);
MF(m3t); MF(m3); MF(W); MF(x);
MF(bigM); MF(g); MF(bigM_k);
MF(bigM_k_t); MF(C_k); MF(q_k);
MF(temp42); MF(temp44); MF(temp21);
MF(temp41); MF(temp22); MF(temp22b);
MF(temp22c); MF(temp12);
MF(g1); MF(g2);
MF(g1t); MF(g2t);
MF(mAi); MF(mBt);
return 1;
}
double gpc_error(const struct gpc_corr*co, const double*x) {
double c = cos(x[2]);
double s = sin(x[2]);
double e[2];
e[0] = c*(co->p[0]) -s*(co->p[1]) + x[0] - co->q[0];
e[1] = s*(co->p[0]) +c*(co->p[1]) + x[1] - co->q[1];
double this_error = e[0]*e[0]*co->C[0][0]+2*e[0]*e[1]*co->C[0][1]+e[1]*e[1]*co->C[1][1];
if(0) /* due to limited numerical precision, error might be negative */
if(this_error < 0) {
fprintf(stderr, "Something fishy: error = %lf e = [%lf %lf] C = [%lf,%lf;%lf,%lf]\n", this_error,
e[0],e[1],co->C[0][0],co->C[0][1],co->C[1][0],co->C[1][1]);
}
return this_error;
}
double gpc_total_error(const struct gpc_corr*co, int n, const double*x){
double error = 0;
for(int i=0;i<n;i++) {
if(!co[i].valid) continue;
error += gpc_error(co+i,x);
}
if(0) /* due to limited numerical precision, error might be negative */
if(error<0) {
fprintf(stderr, "Something fishy!\n");
}
return error;
}
/*
[ C00 ] [ c01 ]
[ ] [ ]
[ C10 ] [ C11 ]
(%o10) Col 1 = [ ] Col 2 = [ ]
[ py C10 + px C00 ] [ py C11 + c01 px ]
[ ] [ ]
[ px C10 - py C00 ] [ px C11 - c01 py ]
[ px C00 + c01 py ]
[ ]
[ py C11 + px C10 ]
[ ]
Col 3 = [ 2 2 ]
[ py C11 + px py C10 + px C00 + c01 px py ]
[ ]
[ 2 2 ]
[ px py C11 + px C10 - px py C00 - c01 py ]
[ c01 px - py C00 ]
[ ]
[ px C11 - py C10 ]
[ ]
Col 4 = [ 2 2 ]
[ px py C11 - py C10 - px py C00 + c01 px ]
[ ]
[ 2 2 ]
[ px C11 - px py C10 + py C00 - c01 px py ]*/
| {
"alphanum_fraction": 0.5118057547,
"avg_line_length": 30.5877192982,
"ext": "c",
"hexsha": "97cb3219208b9042359f92504a4ceb7f06029e62",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f058fb0bc5c4c9b1a590b7536f75b83af35b7785",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "alecone/ROS_project",
"max_forks_repo_path": "src/csm/sm/lib/gpc/gpc.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f058fb0bc5c4c9b1a590b7536f75b83af35b7785",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "alecone/ROS_project",
"max_issues_repo_path": "src/csm/sm/lib/gpc/gpc.c",
"max_line_length": 149,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f058fb0bc5c4c9b1a590b7536f75b83af35b7785",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "alecone/ROS_project",
"max_stars_repo_path": "src/csm/sm/lib/gpc/gpc.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4281,
"size": 10461
} |
/* randist/pascal.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 James Theiler, Brian Gough
*
* 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 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
* 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.
*/
#include <config.h>
#include <math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
/* The Pascal distribution is a negative binomial with valued integer n
prob(k) = (n - 1 + k)!/(n!(k - 1)!) * p^n (1-p)^k for k = 0, 1, ..., n
*/
unsigned int
gsl_ran_pascal (const gsl_rng * r, double p, unsigned int n)
{
/* This is a separate interface for the pascal distribution so that
it can be optimized differently from the negative binomial in
future.
e.g. if n < 10 it might be faster to generate the Pascal
distributions as the sum of geometric variates directly. */
unsigned int k = gsl_ran_negative_binomial (r, p, (double) n);
return k;
}
double
gsl_ran_pascal_pdf (const unsigned int k, const double p, unsigned int n)
{
double P = gsl_ran_negative_binomial_pdf (k, p, (double) n);
return P;
}
| {
"alphanum_fraction": 0.7050445104,
"avg_line_length": 33.0392156863,
"ext": "c",
"hexsha": "38a25a42a8914ed7dc124ff8bfdf6f316227a030",
"lang": "C",
"max_forks_count": 14,
"max_forks_repo_forks_event_max_datetime": "2020-03-12T12:31:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T04:47:52.000Z",
"max_forks_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Brian-ning/HMNE",
"max_forks_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/randist/pascal.c",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e",
"max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "Brian-ning/HMNE",
"max_issues_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/randist/pascal.c",
"max_line_length": 81,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ielomariala/Hex-Game",
"max_stars_repo_path": "gsl-2.6/randist/pascal.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-10T11:31:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-12-18T18:09:25.000Z",
"num_tokens": 465,
"size": 1685
} |
#ifndef LVVMODEL_H
#define LVVMODEL_H
#include <iostream>
#include <iomanip>
using std::fixed;
using std::showpos;
#include <string>
#include <gsl/gsl_multifit.h>
#include <gsl/gsl_poly.h>
#include "lvv.h"
#include "math.h"
using lvv::powi;
namespace lvv {
int const poly_order = 4;
// template<int M>
class Model { public: ///////////////////////////////////////////////////////////// Model Data - μ² polinom fitting
Model () : n(0), m(0), x(NULL), y(NULL), X(NULL), cov(NULL), c(NULL) {}
Model (double _x[], double _y[], int _n, int _m=-1) : n(_n), m(_m), x(_x), y(_y) { //////////////////////////////// CTOR
// N - data points [0..N) ( 5 for NF )
// M - number of model parameters [0..M)
// if polynomial used in model:
// M-1 - poly order C[0]..C[m-1]
assert(_n >= 3 && "not implemented");
if (_m == -1) { // then need autodetect
if (n < 6 ) m = n-2;
else if (n < 10) m = n-3;
else if (n < 20) m = n-4;
}
assert(n >= m);
X = gsl_matrix_alloc (n, m) ; assert(X);
c = gsl_vector_alloc (m ) ; assert(c);
cov = gsl_matrix_alloc (m, m) ; assert(cov);
xv = gsl_vector_view_array (_x, n);
yv = gsl_vector_view_array (_y, n);
///// INIT - PREP MATRIX for POLIFIT
for (i = 0; i<n; i++) for (int p=0; p<m; ++p) gsl_matrix_set (X, i, p, powi(_x[i], p));
///// FIT
gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, m);
// gsl_multifit_linear (X, y, c, cov, &chisq, work); // int gsl_multifit_linear (const gsl_matrix *X, const gsl_vector *y, gsl_vector *c, gsl_matrix *cov, double *chisq, gsl_multifit_linear_workspace *ws)
gsl_multifit_linear_svd (X, &yv.vector, svd_tol, &rank, c, cov, &chisq, work); // int gsl_multifit_linear_svd (const gsl_matrix *X, const gsl_vector *y, double tol, size t* rank, gsl_vector *c, gsl_matrix *cov, double *chisq, gsl_multifit_linear_workspace *ws)
gsl_multifit_linear_free (work);
};
~Model() { ////////////////////////////////////////////////////////////////// DTOR
if(cov) gsl_matrix_free (cov);
if(c ) gsl_vector_free (c);
if(X ) gsl_matrix_free (X);
};
double estimate (const double x) const {
double y_est = gsl_vector_get(c,0) ;
double pow_x = 1.0 ; // x[0,0]^0
for (int p=1; p<m; ++p) {
pow_x *= x;
y_est += gsl_vector_get(c,p)*pow_x;
}
return y_est;
};
double inverse_estimate (const double yy) const {
double xx = -1.0;
double *C=c->data;
if (m>2) {
double c0_save = C[0];
C[0] = c0_save-yy;
struct { double real; double imag; } z[poly_order-1];
int order = poly_order;
//if ( abs(C[poly_order-1]) < 0.000001 ) // reduce polinomial order of last elem == 0
if ( C[poly_order-1] == 0 ) // reduce polinomial order of last elem == 0
order = poly_order-1;
assert (C[poly_order-1] != 0); // hope we don't need to do it twice
// solve
gsl_poly_complex_workspace * w = gsl_poly_complex_workspace_alloc (order);
gsl_poly_complex_solve (gsl_vector_ptr(c,0), order, w, (double *)z);
gsl_poly_complex_workspace_free (w);
// select real root from list of complex roots
double oorr_distance = numeric_limits<double>::max(); // out_of_range root distance to normal interval
bool got_root = false;
bool got_out_of_range_root = false;
double out_of_range_root = -100;
double real_root = -100000;
//double x_step = x[1]-x[0]; // with step p-rmse go from 0.9904215 to 0.9907456
double x_lower_bound = x[0] /* -x_step/2.0 */ ;
double x_upper_bound = x[n-1] /* +x_step/2.0 */ ;
for (int i = 0; i < order-1; i++) { // for all roots
//cerr << " \t("<<i<<") "<< z[2*i] << "+i" << z[2*i+1];
if (abs(z[i].imag) > 0.00000001) continue;
if ( x_lower_bound <= z[i].real && z[i].real <= x_upper_bound) { // in x valid range
real_root = z[i].real;
got_root = true;
//cerr << " rr=" << real_root;
break; // found it
}
double below_lower_distance = x_lower_bound - z[i].real;
if ( below_lower_distance > 0 ) {
if (( got_out_of_range_root && below_lower_distance < oorr_distance ) || ! got_out_of_range_root) {
oorr_distance = below_lower_distance; // new shortest oorr distance
got_out_of_range_root = true;
out_of_range_root = x_lower_bound;
//cerr << " oor=" << out_of_range_root ;
continue;
}
}
double above_upper_distance = z[i].real - x_upper_bound ;
if ( above_upper_distance > 0 ) {
if (( got_out_of_range_root && above_upper_distance < oorr_distance ) || ! got_out_of_range_root) {
oorr_distance = above_upper_distance;
got_out_of_range_root = true;
out_of_range_root = x_upper_bound;
//cerr << " oor=" << out_of_range_root ;
continue;
}
}
};
if (got_root) xx = real_root;
else if (got_out_of_range_root) xx = out_of_range_root;
else { xx=3.66; cerr << "#model::inverse_estimate(): root not found\n"; ; }
//cerr << " ROOT=" << xx << endl;
gsl_vector_set(c, 0, c0_save);
/*
double c0 = gsl_vector_get(c,0);
double c1 = gsl_vector_get(c,1);
double c2 = gsl_vector_get(c,2);
double c3 = gsl_vector_get(c,3);
if ( 0 > (27*pow2(c3)*pow2(yy)+(-54*c0*pow2(c3)+18*c1*c2*c3-4*pow3(c2))*yy+27*pow2(c0)*pow2(c3)+(4*pow3(c1)-18*c0*c1*c2)*c3+4*c0*pow3(c2)-pow2(c1)*pow2(c2))) {
cout << "inverse_estimate-4-1: cannot solve: c0-2" << c0 << " " << c1 << " " << c2 << " " << c3 << " y: " << yy << endl;
return 3.6;
}
if ( 0 > 27*pow2(c3)*pow2(yy)+(-54*c0*pow2(c3)+18*c1*c2*c3-4*pow3(c2))*yy+27*pow2(c0)*pow2(c3)+(4*pow3(c1)-18*c0*c1*c2)*c3+4*c0*pow3(c2)-pow2(c1)*pow2(c2)) {
cout << "inverse_estimate-4-2: cannot solve: c0-2" << c0 << " " << c1 << " " << c2 << " " << c3 << " y: " << yy << endl;
return 3.6;
}
xx = cbrt((sqrt(27*pow2(c3)*pow2(yy)+(-54*c0*pow2(c3)+18*c1*c2*c3-4*pow3(c2))*yy+27*pow2(c0)*pow2(c3)+(4*pow3(c1)-18*c0*c1*c2)*c3+4*c0*pow3(c2)-pow2(c1)*pow2(c2))/(6*sqrt(3)*pow2(c3))-(-27*pow2(c3)*yy+27*c0*pow2(c3)-9*c1*c2*c3+2*pow3(c2))/(54*pow3(c3))))-cbrt((3*c1*c3-pow2(c2))/(9*pow2(c3)*(sqrt(27*pow2(c3)*pow2(yy)+(-54*c0*pow2(c3)+18*c1*c2*c3-4*pow3(c2))*yy+27*pow2(c0)*pow2(c3)+(4*pow3(c1)-18*c0*c1*c2)*c3+4*c0*pow3(c2)-pow2(c1)*pow2(c2))/(6*sqrt(3)*pow2(c3))-(-27*pow2(c3)*yy+27*c0*pow2(c3)-9*c1*c2*c3+2*pow3(c2))/(54*pow3(c3)))))-c2/(3*c3);
} else if (m==3){
double c0 = gsl_vector_get(c,0);
double c1 = gsl_vector_get(c,1);
double c2 = gsl_vector_get(c,2);
if(4*c2*yy-4*c0*c2+pow2(c1) < 0) {
cout << "inverse_estimate-3: cannot solve: c0-2" << c0 << " " << c1 << " " << c2 << " y: " << yy << endl;
return 3.6;
}
xx = (sqrt(4*c2*yy-4*c0*c2+pow2(c1))-c1)/(2*c2);
//xx = -(sqrt(4*c2*yy-4*c0*c2+pow2(c1))+c1)/(2*c2);
*/
} else if (m==2){
double c0 = gsl_vector_get(c,0);
double c1 = gsl_vector_get(c,1);
xx = (yy-c0)/c1;
} else {
assert(false);
}
return xx;
};
void print (string title="") const {
cout << "# :gnuplot: set key bottom; set ytics 0,0.5; set yrange [-0.1:1.1]; set xrange [0:6]; set grid; set pointsize 1.5;"
<< (title.length()>0 ? "set title \" " + title + "\";" : "") <<
"plot "
" \"pipe\" using 1:3 title \"model\" with lines 5, "
" \"pipe\" using 4:2 title \"inv x(y)\" with point 4,"
" \"pipe\" using 1:2 title \"data\" with points 11 "
";\n";
format table(" % 9f %20t % 9f %40t % 9f %60t % 9f\n");
string _("\" \"");
cout << table % "# X" % " Y" % "Y-mod" % "X-mod-inv" ;
for (int i=0; i<n; ++i ) cout << table % x[i] % y[i] % _ % _ ;
for (double xx=0.0; xx<=6.0; xx+=1./3.) cout << table % xx % _ % estimate(xx) % _ ;
for (double yy=0.0; yy<=1.0; yy+=0.05 ) cout << table % _ % yy % _ % inverse_estimate(yy) ;
};
private: // member vars
int n , m;
const static double svd_tol = 0.000001;
size_t rank;
int i;
double xi , yi, ei, chisq;
gsl_vector_view xv , yv;
double * x;
double * y;
gsl_matrix *X , *cov;
public:
gsl_vector *c;
};
} // namespace lvv
#endif // LVVMODEL_H
| {
"alphanum_fraction": 0.5331574117,
"avg_line_length": 36.9322033898,
"ext": "h",
"hexsha": "60251253ed08a1dcaf4a21d0ffba9b637647aeb4",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b610a089103853e7cf970efde2ce4bed9f505090",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lvv/lvvlib",
"max_forks_repo_path": ".old/model.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b610a089103853e7cf970efde2ce4bed9f505090",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lvv/lvvlib",
"max_issues_repo_path": ".old/model.h",
"max_line_length": 552,
"max_stars_count": 13,
"max_stars_repo_head_hexsha": "b610a089103853e7cf970efde2ce4bed9f505090",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lvv/lvvlib",
"max_stars_repo_path": ".old/model.h",
"max_stars_repo_stars_event_max_datetime": "2020-09-14T23:13:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-02-05T12:26:16.000Z",
"num_tokens": 3106,
"size": 8716
} |
/*
This file originates from LibSVM <http://www.csie.ntu.edu.tw/~cjlin/libsvm/>
Copyright (c) 2000-2013 Chih-Chung Chang and Chih-Jen Lin
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither name of copyright holders nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
This file is part of the Princeton FCMA Toolbox-- namely
the "svm_cross_validation_no_shuffle" function, an edited
version of libsvm's "svm_cross_validation"
*/
#ifndef _SVM_H
#define _SVM_H
#define LIBSVM_VERSION 310
#define MAXSVMITERATION 20000000
#if defined(__GNUC__)
// gcc supports this syntax
#define ALIGNED(x) __attribute__((aligned(x)))
#else
// visual c++, clang, icc
#define ALIGNED(x) __declspec(align(x))
#endif
//#include "LibSVM.h"
#include <cassert>
// BLAS dependency
#ifdef USE_MKL
#include <mkl.h>
#else
typedef int MKL_INT;
#if defined __APPLE__
#include <Accelerate/Accelerate.h>
#else
extern "C" {
#include <cblas.h>
}
#endif
#endif
// SSE/AVX instrinsics
#if defined(_MSC_VER)
// Microsoft C/C++-compatible compiler */
#include <intrin.h>
#elif defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__))
// GCC-compatible compiler (gcc,clang,icc) targeting x86/x86-64
#include <x86intrin.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
// unsigned long long counter;
typedef float Qfloat;
typedef signed char schar;
extern int libsvm_version;
// use SOA instead of AOS --later!!
struct svm_node {
int index;
float value;
};
// change y from double to schar, x is one-step pointer now
struct svm_problem {
int l;
schar *y;
struct svm_node **x;
};
struct svm_parameter {
int svm_type;
int kernel_type;
int degree; /* for poly */
double gamma; /* for poly/rbf/sigmoid */
double coef0; /* for poly/sigmoid */
/* these are for training only */
double cache_size; /* in MB */
double eps; /* stopping criteria */
double C; /* for C_SVC, EPSILON_SVR and NU_SVR */
int nr_weight; /* for C_SVC */
int *weight_label; /* for C_SVC */
double *weight; /* for C_SVC */
double nu; /* for NU_SVC, ONE_CLASS, and NU_SVR */
double p; /* for EPSILON_SVR */
int shrinking; /* use the shrinking heuristics */
int probability; /* do probability estimates */
};
//
// svm_model
//
struct svm_model {
struct svm_parameter param; /* parameter */
int nr_class; /* number of classes, = 2 in regression/one class svm */
int l; /* total #SV */
struct svm_node **SV; /* SVs (SV[l]) */
double **sv_coef; /* coefficients for SVs in decision functions
(sv_coef[k-1][l]) */
double *rho; /* constants in decision functions (rho[k*(k-1)/2]) */
/* for classification only */
int *label; /* label of each class (label[k]) */
int *nSV; /* number of SVs for each class (nSV[k]) */
/* nSV[0] + nSV[1] + ... + nSV[k-1] = l */
/* XXX */
int free_sv; /* 1 if svm_model is created by svm_load_model*/
/* 0 if svm_model is created by svm_train */
};
enum {
C_SVC
};
/* svm_type */ // only C_SVC is needed for now
enum {
LINEAR,
PRECOMPUTED
}; /* kernel_type */
typedef struct svm_problem SVMProblem;
typedef struct svm_parameter SVMParameter;
typedef struct svm_node SVMNode;
struct svm_model *svm_train(const struct svm_problem *prob,
const struct svm_parameter *param);
void svm_cross_validation(const struct svm_problem *prob,
const struct svm_parameter *param,
int nr_fold, double *target);
void svm_cross_validation_no_shuffle(const struct svm_problem *prob,
const struct svm_parameter *param,
int nr_fold, double *target);
int svm_get_svm_type(const struct svm_model *model);
int svm_get_nr_class(const struct svm_model *model);
void svm_get_labels(const struct svm_model *model, int *label);
double svm_predict_values(const struct svm_model *model,
const struct svm_node *x, double *dec_values);
double svm_predict(const struct svm_model *model, const struct svm_node *x);
double svm_predict_distance(const struct svm_model *model,
const struct svm_node *x);
void svm_free_model_content(struct svm_model *model_ptr);
void svm_free_and_destroy_model(struct svm_model **model_ptr_ptr);
void svm_destroy_param(struct svm_parameter *param);
const char *svm_check_parameter(const struct svm_problem *prob,
const struct svm_parameter *param);
int svm_check_probability_model(const struct svm_model *model);
void svm_set_print_string_function(void (*print_func)(const char *));
int svm_save_model(const char *model_file_name, const struct svm_model *model);
struct svm_model *svm_load_model(const char *model_file_name);
#ifdef __cplusplus
}
#endif
#endif /* _SVM_H */
| {
"alphanum_fraction": 0.7023561468,
"avg_line_length": 31.351758794,
"ext": "h",
"hexsha": "2b8b4b663d62d65c367c729b6871fdfadb98c5e2",
"lang": "C",
"max_forks_count": 6,
"max_forks_repo_forks_event_max_datetime": "2020-06-08T18:06:26.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-08-26T19:37:29.000Z",
"max_forks_repo_head_hexsha": "74f151d07d683fc2b1612b5b0e2cb29617b69c03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "PrincetonUniversity/fcma-toolbox",
"max_forks_repo_path": "deps/SVM-Simple/svm.h",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "74f151d07d683fc2b1612b5b0e2cb29617b69c03",
"max_issues_repo_issues_event_max_datetime": "2017-07-27T08:11:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-08-17T01:05:36.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "PrincetonUniversity/fcma-toolbox",
"max_issues_repo_path": "deps/SVM-Simple/svm.h",
"max_line_length": 80,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "74f151d07d683fc2b1612b5b0e2cb29617b69c03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "PrincetonUniversity/fcma-toolbox",
"max_stars_repo_path": "deps/SVM-Simple/svm.h",
"max_stars_repo_stars_event_max_datetime": "2019-03-16T17:34:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T04:27:01.000Z",
"num_tokens": 1450,
"size": 6239
} |
/* rng/rng.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough
*
* 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.
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_rng.h>
gsl_rng *
gsl_rng_alloc (const gsl_rng_type * T)
{
gsl_rng *r = (gsl_rng *) malloc (sizeof (gsl_rng));
if (r == 0)
{
GSL_ERROR_VAL ("failed to allocate space for rng struct",
GSL_ENOMEM, 0);
};
r->state = malloc (T->size);
if (r->state == 0)
{
free (r); /* exception in constructor, avoid memory leak */
GSL_ERROR_VAL ("failed to allocate space for rng state",
GSL_ENOMEM, 0);
};
r->type = T;
gsl_rng_set (r, gsl_rng_default_seed); /* seed the generator */
return r;
}
int
gsl_rng_memcpy (gsl_rng * dest, const gsl_rng * src)
{
if (dest->type != src->type)
{
GSL_ERROR ("generators must be of the same type", GSL_EINVAL);
}
memcpy (dest->state, src->state, src->type->size);
return GSL_SUCCESS;
}
gsl_rng *
gsl_rng_clone (const gsl_rng * q)
{
gsl_rng *r = (gsl_rng *) malloc (sizeof (gsl_rng));
if (r == 0)
{
GSL_ERROR_VAL ("failed to allocate space for rng struct",
GSL_ENOMEM, 0);
};
r->state = malloc (q->type->size);
if (r->state == 0)
{
free (r); /* exception in constructor, avoid memory leak */
GSL_ERROR_VAL ("failed to allocate space for rng state",
GSL_ENOMEM, 0);
};
r->type = q->type;
memcpy (r->state, q->state, q->type->size);
return r;
}
void
gsl_rng_set (const gsl_rng * r, unsigned long int seed)
{
(r->type->set) (r->state, seed);
}
#ifndef HIDE_INLINE_STATIC
unsigned long int
gsl_rng_get (const gsl_rng * r)
{
return (r->type->get) (r->state);
}
double
gsl_rng_uniform (const gsl_rng * r)
{
return (r->type->get_double) (r->state);
}
double
gsl_rng_uniform_pos (const gsl_rng * r)
{
double x ;
do
{
x = (r->type->get_double) (r->state) ;
}
while (x == 0) ;
return x ;
}
/* Note: to avoid integer overflow in (range+1) we work with scale =
range/n = (max-min)/n rather than scale=(max-min+1)/n, this reduces
efficiency slightly but avoids having to check for the out of range
value. Note that range is typically O(2^32) so the addition of 1
is negligible in most usage. */
unsigned long int
gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n)
{
unsigned long int offset = r->type->min;
unsigned long int range = r->type->max - offset;
unsigned long int scale;
unsigned long int k;
if (n > range || n == 0)
{
GSL_ERROR_VAL ("invalid n, either 0 or exceeds maximum value of generator",
GSL_EINVAL, 0) ;
}
scale = range / n;
do
{
k = (((r->type->get) (r->state)) - offset) / scale;
}
while (k >= n);
return k;
}
#endif
unsigned long int
gsl_rng_max (const gsl_rng * r)
{
return r->type->max;
}
unsigned long int
gsl_rng_min (const gsl_rng * r)
{
return r->type->min;
}
const char *
gsl_rng_name (const gsl_rng * r)
{
return r->type->name;
}
size_t
gsl_rng_size (const gsl_rng * r)
{
return r->type->size;
}
void *
gsl_rng_state (const gsl_rng * r)
{
return r->state;
}
void
gsl_rng_print_state (const gsl_rng * r)
{
size_t i;
unsigned char *p = (unsigned char *) (r->state);
const size_t n = r->type->size;
for (i = 0; i < n; i++)
{
/* FIXME: we're assuming that a char is 8 bits */
printf ("%.2x", *(p + i));
}
}
void
gsl_rng_free (gsl_rng * r)
{
free (r->state);
free (r);
}
| {
"alphanum_fraction": 0.6206030151,
"avg_line_length": 20.6509433962,
"ext": "c",
"hexsha": "eafdefb5da0e3cbff4b81714f0acd282cf36c955",
"lang": "C",
"max_forks_count": 40,
"max_forks_repo_forks_event_max_datetime": "2022-03-03T23:23:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-26T15:31:16.000Z",
"max_forks_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "manggoguy/parsec-modified",
"max_forks_repo_path": "pkgs/libs/gsl/src/rng/rng.c",
"max_issues_count": 12,
"max_issues_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_issues_repo_issues_event_max_datetime": "2022-03-13T03:54:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-12-15T08:30:19.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "manggoguy/parsec-modified",
"max_issues_repo_path": "pkgs/libs/gsl/src/rng/rng.c",
"max_line_length": 81,
"max_stars_count": 64,
"max_stars_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "manggoguy/parsec-modified",
"max_stars_repo_path": "pkgs/libs/gsl/src/rng/rng.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T13:26:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-06T00:30:56.000Z",
"num_tokens": 1278,
"size": 4378
} |
#include "parameters.h" // Includes all defined parameters
#include "axi.h" // Axisymmetric coordinates
#include "navier-stokes/centered.h" // To solve the Navier-Stokes
#include "two-phase.h" // Implements two-phase flow
// #include <omp.h> // For openMP parallel
#include <gsl/gsl_fit.h>
double * forces_array;
double * times_array;
double gradient = 0.5;
double intercept = 4.9;
int main () {
forces_array = malloc(INTERP_NO * sizeof(double));
times_array = malloc(INTERP_NO * sizeof(double));
DT = 1e-2;
run();
free(forces_array);
free(times_array);
}
event force(i++) {
if (i < INTERP_NO) {
forces_array[i] = gradient * t + intercept;
times_array[i] = t;
} else {
double c0, c1, cov00, cov01, cov11, sumsq;
gsl_fit_linear ( times_array, 1, forces_array, 1, INTERP_NO, &c0, &c1, \
&cov00, &cov01, &cov11, &sumsq);
fprintf(stderr, "t = %g, c0 = %g, c1 = %g\n", t, c0, c1);
double current_force = gradient * t + intercept;
double interp_force = c0 + c1 * t;
fprintf(stderr, "f = %g, f_interp = %g", current_force, interp_force);
fprintf(stderr, "\n");
// #pragma omp critical
for (int j = 0; j < INTERP_NO - 1; j++) {
forces_array[j] = forces_array[j + 1];
times_array[j] = times_array[j + 1];
}
forces_array[INTERP_NO - 1] = current_force;
times_array[INTERP_NO - 1] = t;
}
}
event end(t = 1) {
fprintf(stderr, "Ended\n");
} | {
"alphanum_fraction": 0.587890625,
"avg_line_length": 27.4285714286,
"ext": "c",
"hexsha": "fda2da105df234611cf828b8b3714e0f3d271508",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "353ad2e1b36520b2088d90a362cff0116e1dd248",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "MNegus/plate-impact",
"max_forks_repo_path": "deprecated_code/regression_test/code/regression.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "353ad2e1b36520b2088d90a362cff0116e1dd248",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "MNegus/plate-impact",
"max_issues_repo_path": "deprecated_code/regression_test/code/regression.c",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "353ad2e1b36520b2088d90a362cff0116e1dd248",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "MNegus/plate-impact",
"max_stars_repo_path": "deprecated_code/regression_test/code/regression.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 452,
"size": 1536
} |
/* filter/median.c
*
* Contains routines related to the standard median filter
*
* Copyright (C) 2018 Patrick Alken
*
* 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 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
* 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.
*/
#include <config.h>
#include <stdlib.h>
#include <math.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_filter.h>
#include <gsl/gsl_errno.h>
gsl_filter_median_workspace *
gsl_filter_median_alloc(const size_t K)
{
gsl_filter_median_workspace *w;
size_t H = K / 2;
w = calloc(1, sizeof(gsl_filter_median_workspace));
if (w == 0)
{
GSL_ERROR_NULL ("failed to allocate space for workspace", GSL_ENOMEM);
}
w->movstat_workspace_p = gsl_movstat_alloc(2*H + 1);
if (w->movstat_workspace_p == NULL)
{
gsl_filter_median_free(w);
GSL_ERROR_NULL ("failed to allocate space for movstat workspace", GSL_ENOMEM);
}
return w;
}
void
gsl_filter_median_free(gsl_filter_median_workspace * w)
{
if (w->movstat_workspace_p)
gsl_movstat_free(w->movstat_workspace_p);
free(w);
}
/*
gsl_filter_median()
Standard median filter
Inputs: endtype - end point handling
x - input vector
y - output vector
w - workspace
*/
int
gsl_filter_median(const gsl_filter_end_t endtype, const gsl_vector * x, gsl_vector * y, gsl_filter_median_workspace * w)
{
int status = gsl_movstat_median(endtype, x, y, w->movstat_workspace_p);
return status;
}
| {
"alphanum_fraction": 0.7154432793,
"avg_line_length": 26.8974358974,
"ext": "c",
"hexsha": "85b0c7ce71456febcc46373362b02082a98736f8",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z",
"max_forks_repo_head_hexsha": "83fd1fc4cbd053a4f9b673d5cd5841823ddd4d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "karanbirsandhu/nu-sense",
"max_forks_repo_path": "test/lib/gsl-2.6/filter/median.c",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ielomariala/Hex-Game",
"max_issues_repo_path": "gsl-2.6/filter/median.c",
"max_line_length": 120,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ielomariala/Hex-Game",
"max_stars_repo_path": "gsl-2.6/filter/median.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z",
"num_tokens": 536,
"size": 2098
} |
#include "example_z.h"
#include <stdlib.h>
#include <lapacke.h>
void random_zvec(int len, BBLAS_Complex64_t *vec)
{
// BBLAS_Complex64_t *work =
// (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*len);
// int info = 0;
double scalar = 1.0;
int seed = 2;
int zero = 0;
int one = 1;
int lenm1 = len-1;
int colmaj = BblasColMajor;
LAPACKE_zlagge(colmaj, len, one, lenm1, zero, &scalar, vec, len, &seed);
}
void random_mat(int m, int n, BBLAS_Complex64_t *mat)
{
// BBLAS_Complex64_t *work = malloc(sizeof(BBLAS_Complex64_t)*m*n);
// int info = 0;
double scalar = 1.0;
int seed = 2;
int mm1 = m-1;
int nn1 = n-1;
int colmaj = BblasColMajor;
LAPACKE_zlagge(colmaj, m, n, mm1, nn1, &scalar, mat, m, &seed);
}
BBLAS_Complex64_t randz()
{
BBLAS_Complex64_t val;
random_mat(1, 1, &val);
return val;
}
void set_params_fixed_zgemv(struct zgemv_batchf_example *zgemv_example)
{
int batch_count = rand() % 50;
zgemv_example->batch_count = batch_count;
zgemv_example->trans = rand() % 3+111;
int m = rand() % 200;
zgemv_example->m = m;
int n = rand() % 200;
zgemv_example->n = n;
zgemv_example->alpha = randz();
/* arrayA */
BBLAS_Complex64_t **arrayA =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (int i = 0; i < batch_count; i++)
{
arrayA[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*m*n);
random_mat(m, n, arrayA[i]);
}
zgemv_example->arrayA = arrayA;
zgemv_example->lda = zgemv_example->m;
/* arrayx */
BBLAS_Complex64_t **arrayx =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
int curdim;
if (zgemv_example->trans == BblasNoTrans)
{
curdim = n;
}
else
{
curdim = m;
}
for (int i = 0; i < batch_count; i++)
{
arrayx[i] =
(BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*curdim);
random_zvec(curdim, arrayx[i]);
}
zgemv_example->arrayx = arrayx;
zgemv_example->incx = 1;
zgemv_example->beta = randz();
/* arrayy */
BBLAS_Complex64_t **arrayy =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
if (zgemv_example->trans == BblasNoTrans)
{
curdim = m;
}
else
{
curdim = n;
}
for (int i = 0; i < batch_count; i++)
{
arrayy[i] =
(BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*curdim);
random_zvec(curdim, arrayy[i]);
}
zgemv_example->arrayy = arrayy;
zgemv_example->incy = 1;
}
void set_params_variable_zgemv(struct zgemv_batchv_example *zgemv_example)
{
int batch_count = rand() % 50;
zgemv_example->batch_count = batch_count;
int *trans = (int*) malloc(sizeof(int)*batch_count);
for(int i = 0; i < batch_count; i++)
{
trans[i] = rand() % 3 + 111;
}
zgemv_example->trans = (enum BBLAS_TRANS*) trans;
int *m = (int*) malloc(sizeof(int)*batch_count);
for (int i = 0; i < batch_count; i++)
{
m[i] = rand() % 200;
}
zgemv_example->m = m;
int *n = (int*) malloc(sizeof(int)*batch_count);
for (int i = 0; i < batch_count; i++)
{
n[i] = rand() % 200;
}
zgemv_example->n = n;
BBLAS_Complex64_t *alpha = malloc(sizeof(BBLAS_Complex64_t)*batch_count);
for (int i = 0; i < batch_count; i++)
{
alpha[i] = randz();
}
zgemv_example->alpha = alpha;
/* arrayA */
BBLAS_Complex64_t **arrayA =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (int i = 0; i < batch_count; i++)
{
arrayA[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*m[i]*n[i]);
random_mat(m[i], n[i], arrayA[i]);
}
zgemv_example->arrayA = arrayA;
int *lda = (int*) malloc(sizeof(int)*batch_count);
for (int i = 0; i < batch_count; i++)
{
lda[i] = m[i];
}
zgemv_example->lda = lda;
/* arrayx */
BBLAS_Complex64_t **arrayx =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
int curdim;
for (int i = 0; i < batch_count; i++)
{
if (trans[i] == BblasNoTrans)
{
curdim = n[i];
}
else
{
curdim = m[i];
}
arrayx[i] =
(BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*curdim);
random_zvec(curdim, arrayx[i]);
}
zgemv_example->arrayx = arrayx;
int *incx = (int*) malloc(sizeof(int)*batch_count);
for (int i = 0; i < batch_count; i++)
{
incx[i] = 1;
}
zgemv_example->incx = incx;
BBLAS_Complex64_t *beta = malloc(sizeof(BBLAS_Complex64_t)*batch_count);
for (int i = 0; i < batch_count; i++)
{
beta[i] = randz();
}
zgemv_example->beta = beta;
/* arrayy */
BBLAS_Complex64_t **arrayy =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (int i = 0; i < batch_count; i++)
{
if (trans[i] == BblasNoTrans)
{
curdim = m[i];
}
else
{
curdim = n[i];
}
arrayy[i] =
(BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*curdim);
random_zvec(curdim, arrayy[i]);
}
zgemv_example->arrayy = arrayy;
int *incy = (int*) malloc(sizeof(int)*batch_count);
for (int i = 0; i < batch_count; i++)
{
incy[i] = 1;
}
zgemv_example->incy = incy;
}
void set_params_fixed_zgemm(struct zgemm_batchf_example *zgemm_example)
{
int i;
int batch_count;
int m;
int n;
int k;
int lda;
int ldb;
batch_count = rand() % 5;
zgemm_example->batch_count = batch_count;
zgemm_example->transA = rand() % 3+111;
zgemm_example->transB = rand() % 3+111;
m = rand() % 20;
zgemm_example->m = m;
n = rand() % 20;
zgemm_example->n = n;
k = rand() % 20;
zgemm_example->k = k;
zgemm_example->alpha = randz();
zgemm_example->beta = randz();
/* arrayA */
BBLAS_Complex64_t **arrayA =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (i = 0; i < batch_count; i++)
{
arrayA[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*m*k);
random_mat(m, k, arrayA[i]);
}
zgemm_example->arrayA = arrayA;
if (zgemm_example->transA == BblasNoTrans)
{
lda = m;
}
else
{
lda = k;
}
zgemm_example->lda = lda;
/* arrayB */
BBLAS_Complex64_t **arrayB =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (i = 0; i < batch_count; i++)
{
arrayB[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*k*n);
random_mat(k, n, arrayB[i]);
}
zgemm_example->arrayB = arrayB;
if (zgemm_example->transB == BblasNoTrans)
{
ldb = k;
}
else
{
ldb = n;
}
zgemm_example->ldb = ldb;
/* arrayC */
BBLAS_Complex64_t **arrayC =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (i = 0; i < batch_count; i++)
{
arrayC[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*m*n);
random_mat(m, n, arrayC[i]);
}
zgemm_example->arrayC = arrayC;
zgemm_example->ldc = m;
}
// One pointer (op) approach
void set_params_fixed_zgemm_stride(struct zgemm_batchf_example_stride *zgemm_example)
{
int i;
int batch_count;
int m;
int n;
int k;
int lda;
int ldb;
enum BBLAS_TRANS transA;
enum BBLAS_TRANS transB;
batch_count = rand() % 5;
zgemm_example->batch_count = batch_count;
transA = BblasNoTrans;
zgemm_example->transA = transA;
transB = BblasNoTrans;
zgemm_example->transB = transB;
m = rand() % 20;
zgemm_example->m = m;
n = rand() % 20;
zgemm_example->n = n;
k = rand() % 20;
zgemm_example->k = k;
zgemm_example->alpha = randz();
zgemm_example->beta = randz();
/* arrayA */
BBLAS_Complex64_t *arrayA =
(BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*batch_count*m*k);
for (i = 0; i < batch_count; i++)
{
random_mat(m, k, &arrayA[i*m*k]);
}
zgemm_example->arrayA = arrayA;
if (zgemm_example->transA == BblasNoTrans)
{
lda = m;
}
else
{
lda = k;
}
zgemm_example->lda = lda;
zgemm_example->strideA = m*k;
/* arrayB */
BBLAS_Complex64_t *arrayB =
(BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t*)*batch_count*k*n);
for (i = 0; i < batch_count; i++)
{
random_mat(k, n, &arrayB[i*k*n]);
}
zgemm_example->arrayB = arrayB;
if (zgemm_example->transB == BblasNoTrans)
{
ldb = k;
}
else
{
ldb = n;
}
zgemm_example->ldb = ldb;
zgemm_example->strideB = k*n;
/* arrayC */
BBLAS_Complex64_t *arrayC =
(BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t*)*batch_count*m*n);
for (i = 0; i < batch_count; i++)
{
random_mat(m, n, &arrayC[i*m*n]);
}
zgemm_example->arrayC = arrayC;
zgemm_example->ldc = m;
zgemm_example->strideC = m*n;
}
void set_params_variable_zgemm(struct zgemm_batchv_example *zgemm_example)
{
int i;
int batch_count;
int lda;
int ldb;
batch_count = rand() % 5;
zgemm_example->batch_count = batch_count;
for (i = 0; i < batch_count; i++)
{
zgemm_example->transA[i] = rand() % 3+111;
zgemm_example->transB[i] = rand() % 3+111;
zgemm_example->m[i] = rand() % 20;
zgemm_example->n[i] = rand() % 20;
zgemm_example->k[i] = rand() % 20;
zgemm_example->alpha[i] = randz();
zgemm_example->beta[i] = randz();
}
/* arrayA */
BBLAS_Complex64_t **arrayA =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (i = 0; i < batch_count; i++)
{
arrayA[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*
zgemm_example->m[i]*zgemm_example->k[i]);
random_mat(zgemm_example->m[i], zgemm_example->k[i], arrayA[i]);
if (zgemm_example->transA[i] == BblasNoTrans)
{
lda = zgemm_example->m[i];
}
else
{
lda = zgemm_example->k[i];
}
zgemm_example->lda[i] = lda;
}
zgemm_example->arrayA = arrayA;
/* arrayB */
BBLAS_Complex64_t **arrayB =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (i = 0; i < batch_count; i++)
{
arrayB[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*
zgemm_example->k[i]*zgemm_example->n[i]);
random_mat(zgemm_example->k[i], zgemm_example->n[i], arrayB[i]);
if (zgemm_example->transB[i] == BblasNoTrans)
{
ldb = zgemm_example->k[i];
}
else
{
ldb = zgemm_example->n[i];
}
zgemm_example->ldb[i] = ldb;
}
zgemm_example->arrayB = arrayB;
/* arrayC */
BBLAS_Complex64_t **arrayC =
(BBLAS_Complex64_t**) malloc(sizeof(BBLAS_Complex64_t*)*batch_count);
for (i = 0; i < batch_count; i++)
{
arrayC[i] = (BBLAS_Complex64_t*) malloc(sizeof(BBLAS_Complex64_t)*
zgemm_example->m[i]*zgemm_example->n[i]);
random_mat(zgemm_example->m[i], zgemm_example->n[i], arrayC[i]);
zgemm_example->ldc[i] = zgemm_example->m[i];
}
zgemm_example->arrayC = arrayC;
}
| {
"alphanum_fraction": 0.6472232935,
"avg_line_length": 24.2903981265,
"ext": "c",
"hexsha": "d3be0ece521edf49f3a0df9ccb4e85d3d9ffa440",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "117f3538b3ab43ade0ad53950ecac25c1a192bc7",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "sdrelton/bblas_api_test",
"max_forks_repo_path": "examples/testing_utils.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "117f3538b3ab43ade0ad53950ecac25c1a192bc7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "sdrelton/bblas_api_test",
"max_issues_repo_path": "examples/testing_utils.c",
"max_line_length": 85,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "3df5d3379b73d4716d4850aaa9f04e808d2c850a",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "mawussi/BBLAS-group",
"max_stars_repo_path": "examples/testing_utils.c",
"max_stars_repo_stars_event_max_datetime": "2016-08-31T22:24:49.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-08-04T11:59:07.000Z",
"num_tokens": 3719,
"size": 10372
} |
/*
gcc-mp-4.8 -O3 cudaddottest.c common.c -o cudaddottest -I../../../../netlib/CBLAS -I/usr/local/cuda/include/ -L/usr/local/cuda/lib -lcublas
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib
./cudaddottest > ../../../results/mac_os_x-x86_64-ddot-cuda_nooh.csv
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cblas.h>
#include "common.h"
#include <cublas.h>
void checkStatus(char* message, cublasStatus status) {
if (status != CUBLAS_STATUS_SUCCESS) {
fprintf (stderr, "!!!! %s fail %d\n", message, status);
exit(EXIT_FAILURE);
}
}
long benchmark(int size) {
long requestStart, requestEnd;
int incx = 1, incy = 1, n = size;
double *cuA, *cuB;
cublasStatus status;
double* a = random_array(size);
double* b = random_array(size);
status = cublasAlloc(n, sizeof(double),(void**)&cuA);
checkStatus("A", status);
status = cublasAlloc(n, sizeof(double),(void**)&cuB);
checkStatus("B", status);
status = cublasSetVector(n, sizeof(double), a, incx, cuA, incx);
checkStatus("setA", status);
status = cublasSetVector(n, sizeof(double), b, incy, cuB, incy);
checkStatus("setB", status);
requestStart = currentTimeNanos();
cublasDdot(n, cuA, incx, cuB, incy);
requestEnd = currentTimeNanos();
status = cublasFree(cuA);
checkStatus("freeA", status);
status = cublasFree(cuB);
checkStatus("freeB", status);
free(a);
free(b);
return (requestEnd - requestStart);
}
main()
{
cublasStatus status;
status = cublasInit();
checkStatus("init", status);
srand(time(NULL));
double factor = 6.0 / 100.0;
int i, j;
for (i = 0 ; i < 10 ; i++) {
for (j = 1 ; j <= 100 ; j++) {
int size = (int) pow(10.0, factor * j);
if (size < 10) continue;
long took = benchmark(size);
printf("\"%d\",\"%lu\"\n", size, took);
}
}
} | {
"alphanum_fraction": 0.6185402238,
"avg_line_length": 23.1728395062,
"ext": "c",
"hexsha": "206da6481e80a56afaedab458a00afe8477e8ac2",
"lang": "C",
"max_forks_count": 154,
"max_forks_repo_forks_event_max_datetime": "2021-09-07T04:58:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T22:48:26.000Z",
"max_forks_repo_head_hexsha": "38a78797d57339395bf10f3d65baeda8570d27e3",
"max_forks_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_forks_repo_name": "debasish83/netlib-java",
"max_forks_repo_path": "perf/src/main/c/cudaddottest.c",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "38a78797d57339395bf10f3d65baeda8570d27e3",
"max_issues_repo_issues_event_max_datetime": "2017-07-24T14:20:38.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-01T10:34:19.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_issues_repo_name": "debasish83/netlib-java",
"max_issues_repo_path": "perf/src/main/c/cudaddottest.c",
"max_line_length": 139,
"max_stars_count": 624,
"max_stars_repo_head_hexsha": "38a78797d57339395bf10f3d65baeda8570d27e3",
"max_stars_repo_licenses": [
"BSD-3-Clause-Open-MPI"
],
"max_stars_repo_name": "debasish83/netlib-java",
"max_stars_repo_path": "perf/src/main/c/cudaddottest.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T22:06:35.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-10T02:29:22.000Z",
"num_tokens": 566,
"size": 1877
} |
#pragma once
#include <src/common/Span.h>
#include <gsl/gsl>
#include <type_traits>
namespace miner {
//simple replacement for std::vector<char> in situations where huge
//allocations happen, since the standard doesn't define how
//much more memory std::vector allocates on reserve or resize.
//basically an owning gsl::span
template<class T = uint8_t>
class DynamicBuffer {
gsl::owner<T*> owner = nullptr;
span<T> buffer;
public:
DynamicBuffer() = default;
// only use alignment if a stronger power of two alignment than the natural alignment of T is needed
DynamicBuffer(size_t size, size_t alignment = alignof(T))
: owner(reinterpret_cast<T*>(::operator new(size * sizeof(T) + alignment - 1)))
, buffer(reinterpret_cast<T*>((uintptr_t(owner) + alignment - 1) & ~uintptr_t(alignment - 1))
, ptrdiff_t(size)) {
if (!std::is_trivially_constructible<T>::value) {
new(buffer.data()) T[size];
}
}
~DynamicBuffer() {
if (owner) { //if not moved-from
if (!std::is_trivially_destructible<T>::value) {
for (auto &element : buffer) {
element.~T();
}
}
::operator delete(owner);
}
}
DynamicBuffer(DynamicBuffer &&o) noexcept
: owner(o.owner)
, buffer(o.buffer) {
o.owner = nullptr; //remove ownership
}
DynamicBuffer &operator=(DynamicBuffer &&o) noexcept {
owner = o.owner;
buffer = o.buffer;
o.owner = nullptr; //remove ownership
return *this;
}
//copy
DynamicBuffer(const DynamicBuffer &) = delete;
DynamicBuffer &operator=(const DynamicBuffer &) = delete;
T *data() {
return buffer.data();
}
uint8_t *bytes() {
return reinterpret_cast<uint8_t*>(buffer.data());
}
const T *data() const {
return buffer.data();
}
const uint8_t *bytes() const {
return reinterpret_cast<const uint8_t*>(buffer.data());
}
size_t size_bytes() const {
return static_cast<size_t>(buffer.size_bytes());
}
size_t size() const {
return static_cast<size_t>(buffer.size());
}
span<const T> getSpan() const {
return buffer;
}
span<const uint8_t> getByteSpan() const {
return {bytes(), static_cast<ptrdiff_t>(size_bytes())};
}
operator bool() const {
return owner != nullptr;
}
};
}
| {
"alphanum_fraction": 0.5320836337,
"avg_line_length": 27.1960784314,
"ext": "h",
"hexsha": "d37aff855f57403abfd667bb800dbf6055a6e5a3",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "492804079eb223e6d4ffd5f5f44283162eaf421b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oldas1/Riner",
"max_forks_repo_path": "src/util/DynamicBuffer.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "492804079eb223e6d4ffd5f5f44283162eaf421b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oldas1/Riner",
"max_issues_repo_path": "src/util/DynamicBuffer.h",
"max_line_length": 108,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "492804079eb223e6d4ffd5f5f44283162eaf421b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oldas1/Riner",
"max_stars_repo_path": "src/util/DynamicBuffer.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 588,
"size": 2774
} |
/* randist/nbinomial.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 James Theiler, Brian Gough
*
* 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 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
* 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.
*/
#include <config.h>
#include <math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_sf_gamma.h>
/* The negative binomial distribution has the form,
prob(k) = Gamma(n + k)/(Gamma(n) Gamma(k + 1)) p^n (1-p)^k
for k = 0, 1, ... . Note that n does not have to be an integer.
This is the Leger's algorithm (given in the answers in Knuth) */
unsigned int
gsl_ran_negative_binomial (const gsl_rng * r, double p, double n)
{
double X = gsl_ran_gamma (r, n, 1.0) ;
unsigned int k = gsl_ran_poisson (r, X*(1-p)/p) ;
return k ;
}
double
gsl_ran_negative_binomial_pdf (const unsigned int k, const double p, double n)
{
double P;
double f = gsl_sf_lngamma (k + n) ;
double a = gsl_sf_lngamma (n) ;
double b = gsl_sf_lngamma (k + 1.0) ;
P = exp(f-a-b) * pow (p, n) * pow (1 - p, (double)k);
return P;
}
| {
"alphanum_fraction": 0.6901241869,
"avg_line_length": 30.7454545455,
"ext": "c",
"hexsha": "7542f360e5e5610201189e2a6e6a4e94fda36e99",
"lang": "C",
"max_forks_count": 14,
"max_forks_repo_forks_event_max_datetime": "2020-03-12T12:31:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T04:47:52.000Z",
"max_forks_repo_head_hexsha": "0cb4635af7602f2a243a9b739e5ed757424ab2a7",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "skair39/structured",
"max_forks_repo_path": "CMVS-PMVS/program/thirdParty/gsl-1.13/randist/nbinomial.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0cb4635af7602f2a243a9b739e5ed757424ab2a7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "skair39/structured",
"max_issues_repo_path": "CMVS-PMVS/program/thirdParty/gsl-1.13/randist/nbinomial.c",
"max_line_length": 81,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "92728bb89692fda1705a0dee436592d97922a6cb",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "parasol-ppl/PPL_utils",
"max_stars_repo_path": "folding_libs/gsl-1.14/randist/nbinomial.c",
"max_stars_repo_stars_event_max_datetime": "2021-11-25T17:31:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-11T02:53:04.000Z",
"num_tokens": 506,
"size": 1691
} |
#ifndef _PK_SLOPE_H_
#define _PK_SLOPE_H_
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
#include <vector_types.h>
#include <gsl/gsl_deriv.h>
#include "cspline.h"
#include "file_check.h"
template <typename T> class pkSlope{
int N;
std::vector<T> k, Pk, n;
cspline<T> slope;
void get_pk_spline();
void calculate_n();
void get_n_spline();
public:
cspline<T> power;
pkSlope();
pkSlope(std::string in_pk_file);
void initialize(std::string in_pk_file);
void calculate();
void get_device_spline(std::vector<float4> &d_spline);
void get_device_spline(std::vector<double4> &d_spline);
};
template <typename T> double f(double x, void *params) {
cspline<T> Pow = *(cspline<T> *)params;
return Pow.evaluate(x);
}
template <typename T> void pkSlope<T>::get_pk_spline() {
pkSlope<T>::power.initialize(pkSlope<T>::k, pkSlope<T>::Pk);
}
template <typename T> void pkSlope<T>::calculate_n() {
gsl_function F;
double result, err;
F.function = &f<T>;
F.params = &power;
for (int i = 0; i < pkSlope<T>::N; ++i) {
if (i == 0) {
gsl_deriv_forward(&F, pkSlope<T>::k[i], 1e-8, &result, &err);
} else if (i == pkSlope<T>::N - 1) {
gsl_deriv_backward(&F, pkSlope<T>::k[i], 1e-8, &result, &err);
} else {
gsl_deriv_central(&F, pkSlope<T>::k[i], 1e-8, &result, &err);
}
pkSlope<T>::n.push_back(result);
}
}
template <typename T> void pkSlope<T>::get_n_spline() {
pkSlope<T>::slope.initialize(pkSlope<T>::k, pkSlope<T>::n);
}
template <typename T> pkSlope<T>::pkSlope() {
pkSlope<T>::N = 0;
}
template <typename T> pkSlope<T>::pkSlope(std::string in_pk_file) {
pkSlope<T>::initialize(in_pk_file);
}
template <typename T> void pkSlope<T>::initialize(std::string in_pk_file) {
if (check_file_exists(in_pk_file)) {
std::ifstream fin(in_pk_file);
while(!fin.eof()) {
T kt, pt;
fin >> kt >> pt;
if (!fin.eof()) {
pkSlope<T>::k.push_back(log10(kt));
pkSlope<T>::Pk.push_back(log10(pt));
}
}
fin.close();
pkSlope<T>::N = pkSlope<T>::k.size();
}
}
template <typename T> void pkSlope<T>::calculate() {
pkSlope<T>::get_pk_spline();
pkSlope<T>::calculate_n();
pkSlope<T>::get_n_spline();
}
template <typename T> void pkSlope<T>::get_device_spline(std::vector<float4> &d_spline) {
pkSlope<T>::slope.set_pointer_for_device(d_spline);
}
template <typename T> void pkSlope<T>::get_device_spline(std::vector<double4> &d_spline) {
pkSlope<T>::slope.set_pointer_for_device(d_spline);
}
#endif
| {
"alphanum_fraction": 0.5821629213,
"avg_line_length": 25.203539823,
"ext": "h",
"hexsha": "f1544062afe6fb29aa52bdaa74d33d496871f421",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6fd93c1f75c190629ec272786c46ff46d9d7bd98",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dpearson1983/BIMODAL",
"max_forks_repo_path": "include/pk_slope.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6fd93c1f75c190629ec272786c46ff46d9d7bd98",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dpearson1983/BIMODAL",
"max_issues_repo_path": "include/pk_slope.h",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6fd93c1f75c190629ec272786c46ff46d9d7bd98",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dpearson1983/BIMODAL",
"max_stars_repo_path": "include/pk_slope.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 826,
"size": 2848
} |
/*
Copyright [2017-2021] [IBM Corporation]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef MCAS_HSTORE_HEAP_MC_EPHEMERAL_H
#define MCAS_HSTORE_HEAP_MC_EPHEMERAL_H
#include "heap_mm_ephemeral.h"
#include "hstore_config.h"
#include "histogram_log2.h"
#include "hop_hash_log.h"
#include <mm_plugin_itf.h>
#include "persistent.h"
#include <ccpm/cca.h> /* ctor_args */
#include <ccpm/interfaces.h> /* ownership_callback, (IHeap_expandable, region_vector_t) */
#include <common/byte_span.h>
#include <common/string_view.h>
#include <nupm/region_descriptor.h>
#include <gsl/span>
#include <algorithm> /* min, swap */
#include <cstddef> /* size_t */
#include <functional> /* function */
#include <memory> /* unique_ptr */
#include <vector>
namespace impl
{
struct allocation_state_pin;
struct allocation_state_emplace;
struct allocation_state_extend;
}
struct heap_mc_ephemeral
: public heap_mm_ephemeral
{
private:
using byte_span = common::byte_span;
using string_view = common::string_view;
std::unique_ptr<
ccpm::IHeap_expandable
> _heap;
impl::allocation_state_emplace *_ase;
impl::allocation_state_pin *_aspd;
impl::allocation_state_pin *_aspk;
impl::allocation_state_extend *_asx;
static constexpr unsigned log_min_alignment = 3U; /* log (sizeof(void *)) */
static_assert(sizeof(void *) == 1U << log_min_alignment, "log_min_alignment does not match sizeof(void *)");
/* Rca_LB seems not to allocate at or above about 2GiB. Limit reporting to 16 GiB. */
static constexpr unsigned hist_report_upper_bound = 34U;
explicit heap_mc_ephemeral(
unsigned debug_level_
, bool restore_not_clear
, impl::allocation_state_emplace *ase
, impl::allocation_state_pin *aspd
, impl::allocation_state_pin *aspk
, impl::allocation_state_extend *asx
, std::unique_ptr<ccpm::IHeap_expandable> p
, string_view id
, string_view backing_file
, const std::vector<byte_span> rv_full
, const byte_span pool0_heap
);
public:
friend struct heap_mc;
friend struct heap_mm;
using common::log_source::debug_level;
/* heap_mm version */
explicit heap_mc_ephemeral(
unsigned debug_level
, bool restore_not_clear
, MM_plugin_wrapper &&pw
, impl::allocation_state_emplace *ase
, impl::allocation_state_pin *aspd
, impl::allocation_state_pin *aspk
, impl::allocation_state_extend *asx
, string_view id
, string_view backing_file
, const std::vector<byte_span> rv_full
, byte_span pool0_heap_
);
std::size_t allocated() const override; // { return _allocated; }
std::size_t capacity() const override; // { return _capacity; }
void allocate(persistent_t<void *> &p, std::size_t sz, std::size_t alignment) override;
std::size_t free(persistent_t<void *> &p_, std::size_t sz_) override;
void free_tracked(const void *p, std::size_t sz) override;
heap_mc_ephemeral(const heap_mc_ephemeral &) = delete;
heap_mc_ephemeral& operator=(const heap_mc_ephemeral &) = delete;
void add_managed_region_to_heap(byte_span r_heap) override;
void reconstitute_managed_region_to_heap(byte_span r_heap, ccpm::ownership_callback_t f) override;
bool is_crash_consistent() const override;
bool can_reconstitute() const override;
};
#endif
| {
"alphanum_fraction": 0.7615947925,
"avg_line_length": 32.9196428571,
"ext": "h",
"hexsha": "8be4a9b6fbd1a53068f4c8b1b889a967e94d0c34",
"lang": "C",
"max_forks_count": 13,
"max_forks_repo_forks_event_max_datetime": "2022-01-26T01:56:42.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-02T06:30:36.000Z",
"max_forks_repo_head_hexsha": "f47aab12754c91ebd75b0e1881c8a7cc7aa81278",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "omriarad/mcas",
"max_forks_repo_path": "src/components/store/hstore/src/heap_mc_ephemeral.h",
"max_issues_count": 66,
"max_issues_repo_head_hexsha": "f47aab12754c91ebd75b0e1881c8a7cc7aa81278",
"max_issues_repo_issues_event_max_datetime": "2022-03-07T20:34:52.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-03T23:40:48.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "omriarad/mcas",
"max_issues_repo_path": "src/components/store/hstore/src/heap_mc_ephemeral.h",
"max_line_length": 109,
"max_stars_count": 60,
"max_stars_repo_head_hexsha": "f47aab12754c91ebd75b0e1881c8a7cc7aa81278",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "omriarad/mcas",
"max_stars_repo_path": "src/components/store/hstore/src/heap_mc_ephemeral.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T10:35:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-28T08:15:07.000Z",
"num_tokens": 961,
"size": 3687
} |
/**
* VGMTrans (c) - 2002-2021
* Licensed under the zlib license
* See the included LICENSE for more information
*/
#pragma once
#include <vector>
#include <fluidsynth.h>
#include <gsl-lite.hpp>
class MusicPlayer {
public:
MusicPlayer();
~MusicPlayer();
/**
* Toggles the status of the player
* @returns true if the player is playing
*/
bool toggle();
/**
* Stops the player (unloads resources)
*/
void stop();
/**
* Moves the player position
* @param position relative to song start
*/
void seek(int position);
/**
* Loads SF2 and MIDI data into the player; resources are copied
* @param soundfont_data
* @param midi_data
* @return true if data was loaded correctly
*/
bool loadDataAndPlay(gsl::span<char> soundfont_data, gsl::span<char> midi_data);
/**
* Checks whether the player is playing
* @return true if playing
*/
[[nodiscard]] bool playing() const;
/**
* The number of MIDI ticks elapsed since the player was started
* @return number of ticks relative to song start
*/
[[nodiscard]] int elapsedTicks() const;
/**
* The total number of MIDI ticks in the song
* @return total ticks in the song
*/
[[nodiscard]] int totalTicks() const;
/**
* Gets all the audio driver the player supports
* @return the driver list
*/
[[nodiscard]] std::vector<const char *> getAvailableDrivers() const;
/**
* Changes the current audio driver and restarts playing
* @param driver_name
* @return true if the driver changed
*/
bool setAudioDriver(const char* driver_name);
private:
fluid_settings_t *m_settings = nullptr;
fluid_synth_t *m_synth = nullptr;
fluid_audio_driver_t *m_active_driver = nullptr;
fluid_player_t *m_active_player = nullptr;
void makeSettings();
void makeSynth();
void makePlayer();
};
| {
"alphanum_fraction": 0.676056338,
"avg_line_length": 23.3670886076,
"ext": "h",
"hexsha": "280506245c0624c429d9cc85bf806c4279b72249",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c5f424b9bfbc509a5a7dd675d4502ae2fb3e8c41",
"max_forks_repo_licenses": [
"Zlib"
],
"max_forks_repo_name": "RGBA-CRT/vgmtrans",
"max_forks_repo_path": "src/common/MusicPlayer.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c5f424b9bfbc509a5a7dd675d4502ae2fb3e8c41",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Zlib"
],
"max_issues_repo_name": "RGBA-CRT/vgmtrans",
"max_issues_repo_path": "src/common/MusicPlayer.h",
"max_line_length": 82,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "b48cb0e54f3a319c53de17fc76224d1a711e35ea",
"max_stars_repo_licenses": [
"Zlib"
],
"max_stars_repo_name": "Oipo/vgmtrans",
"max_stars_repo_path": "src/common/MusicPlayer.h",
"max_stars_repo_stars_event_max_datetime": "2015-12-08T18:04:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-12-08T18:04:47.000Z",
"num_tokens": 465,
"size": 1846
} |
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <time.h>
double ar1_ts (double * params, int n, gsl_rng * r)
{
double beta = params[0];
double alpha = params[1];
double s = params[2];
int i;
double x = beta / (1 - alpha); // Start at mean of stationary dist
double sum = 0;
for (i = 1; i <= n; i++) {
sum += x;
x = beta + alpha * x + gsl_ran_gaussian(r, s);
}
return sum / n;
}
int main(void)
{
clock_t start, end;
double cpu_time_used;
int N = 1e7;
double beta = 1.0;
double alpha = 0.9;
double s = 1;
double params[3] = {beta, alpha, s};
/* create a generator via GSL_RNG_TYPE */
const gsl_rng_type * T;
gsl_rng * r;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc(T);
gsl_rng_set(r, 1);
start = clock();
double sample_mean = ar1_ts(params, N, r);
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
gsl_rng_free (r);
printf("mean = %g\n", sample_mean);
printf("time elapsed = %g seconds\n", cpu_time_used);
return 0;
}
| {
"alphanum_fraction": 0.5727739726,
"avg_line_length": 20.8571428571,
"ext": "c",
"hexsha": "9434d58079b4dea15732c9d35e7464b4b441b33a",
"lang": "C",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2019-12-31T21:50:48.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-01-08T18:46:49.000Z",
"max_forks_repo_head_hexsha": "20a9f2feb9b54a73d6d2c79e0824eb528f7e1f11",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tomas-rampas/RBA_RBNZ_Workshops",
"max_forks_repo_path": "john/fast_loop_examples/ar1_sample_mean.c",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "20a9f2feb9b54a73d6d2c79e0824eb528f7e1f11",
"max_issues_repo_issues_event_max_datetime": "2016-11-27T09:38:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-11-27T09:38:18.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "tomas-rampas/RBA_RBNZ_Workshops",
"max_issues_repo_path": "john/fast_loop_examples/ar1_sample_mean.c",
"max_line_length": 71,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "20a9f2feb9b54a73d6d2c79e0824eb528f7e1f11",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "QuantEcon/RBA_RBNZ_Workshops",
"max_stars_repo_path": "john/fast_loop_examples/ar1_sample_mean.c",
"max_stars_repo_stars_event_max_datetime": "2021-12-29T09:01:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-02-07T22:07:34.000Z",
"num_tokens": 360,
"size": 1168
} |
#pragma once
#include <cstddef>
#include <gsl/string_span>
#include <map>
#include <memory>
#include <string_view>
#include <vector>
namespace multihash {
using string_span = gsl::span<char>;
class algorithm {
public:
/** Compute the hash of an input range */
template <typename InputIterator>
auto digest(InputIterator first, InputIterator last) -> std::string;
/** Write the hash of an input range into output */
template <typename InputIterator, typename OutputIterator>
auto digest(InputIterator first, InputIterator last,
OutputIterator output) -> OutputIterator;
virtual ~algorithm() = default;
private:
virtual void reset() = 0;
virtual std::size_t digest_size() const = 0;
virtual std::size_t block_size() const = 0;
virtual void update(std::string_view data) = 0;
virtual std::size_t digest(string_span output) = 0;
std::string digest();
};
template <typename InputIterator>
auto algorithm::digest(InputIterator first, InputIterator last) -> std::string {
auto result = std::string{};
result.reserve(digest_size());
digest(first, last, std::back_inserter(result));
return result;
}
template <typename InputIterator, typename OutputIterator>
auto algorithm::digest(InputIterator first, InputIterator last,
OutputIterator output) -> OutputIterator {
reset();
auto buffer = std::vector<char>{};
auto chunk_size = block_size();
buffer.reserve(chunk_size);
while (first != last) {
for (auto i = 0u; first != last && i < chunk_size; ++i, ++first) {
buffer.emplace_back(*first);
}
auto view = std::string_view(buffer.data(), buffer.size());
update(view);
buffer.clear();
}
auto result = digest();
std::copy(result.begin(), result.end(), output);
return output;
}
} // namespace multihash | {
"alphanum_fraction": 0.6857610475,
"avg_line_length": 27.7727272727,
"ext": "h",
"hexsha": "053864beef5da3fb6e4e98cad9eeb73df32078b2",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-07-15T08:51:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-05-29T06:15:04.000Z",
"max_forks_repo_head_hexsha": "9f26e84082514a1278c1ba1767fe3d067724b26a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cpp-ipfs/cpp-multihash",
"max_forks_repo_path": "multihash/algorithm.h",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "9f26e84082514a1278c1ba1767fe3d067724b26a",
"max_issues_repo_issues_event_max_datetime": "2018-12-14T19:39:21.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-12-13T18:04:07.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cpp-ipfs/cpp-multihash",
"max_issues_repo_path": "multihash/algorithm.h",
"max_line_length": 80,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "9f26e84082514a1278c1ba1767fe3d067724b26a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lockblox/multihash",
"max_stars_repo_path": "multihash/algorithm.h",
"max_stars_repo_stars_event_max_datetime": "2021-10-31T19:35:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-26T11:25:01.000Z",
"num_tokens": 421,
"size": 1833
} |
#ifndef __SAMPLER_H__
#define __SAMPLER_H__
#include <dSFMT.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_rng.h>
class Sampler {
dsfmt_t dsfmt;
void init_random(unsigned params_random_seed) {
#ifdef USE_MT_RANDOM
dsfmt_init_gen_rand(&dsfmt, params_random_seed);
#else
srand(params_random_seed);
#endif
};
protected:
/* gsl random number generator */
gsl_rng* _gsl_rng;
/* default constructor */
Sampler(unsigned int random_seed) {
/* do i still need this ? */
init_random(random_seed);
/* init gsl random number generator */
_gsl_rng = gsl_rng_alloc( gsl_rng_taus );
};
double sample_uniform();
unsigned long int sample_integer_uniform(unsigned int from, unsigned int to);
};
#endif
| {
"alphanum_fraction": 0.7169811321,
"avg_line_length": 19.0256410256,
"ext": "h",
"hexsha": "0215c4ef2aab5f47f6c1bc86d280a3384a60fba3",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-03-03T04:58:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-03-03T04:58:44.000Z",
"max_forks_repo_head_hexsha": "2f7caf51b1e8bf5e510ce91070d622c8119e9865",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ypetinot/web-summarization",
"max_forks_repo_path": "models/topic-models/template-modeling/src/sampler.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2f7caf51b1e8bf5e510ce91070d622c8119e9865",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "ypetinot/web-summarization",
"max_issues_repo_path": "models/topic-models/template-modeling/src/sampler.h",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2f7caf51b1e8bf5e510ce91070d622c8119e9865",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ypetinot/web-summarization",
"max_stars_repo_path": "models/topic-models/template-modeling/src/sampler.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 187,
"size": 742
} |
/* multilarge_nlinear/cgst.c
*
* Copyright (C) 2016 Patrick Alken
*
* 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 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
* 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.
*/
#include <config.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_multilarge_nlinear.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_blas.h>
/*
* This module contains an implementation of the Steihaug-Toint
* conjugate gradient algorithm for nonlinear optimization problems.
* This implementation closely follows the following works:
*
* [1] T. Steihaug, The conjugate gradient method and trust regions
* in large scale optimization, SIAM J. Num. Anal., 20(3) 1983.
*
* In the below algorithm, the Jacobian and gradient are scaled
* according to:
*
* J~ = J D^{-1}
* g~ = D^{-1}
*
* prior to any calculations which results in better numerical
* stability when solving for the Gauss-Newton step. The resulting
* step vector is then backtransformed as:
*
* dx = D^{-1} dx~
*/
typedef struct
{
size_t n; /* number of observations */
size_t p; /* number of parameters */
gsl_vector *z; /* Gauss-Newton step, size p */
gsl_vector *r; /* steepest descent step, size p */
gsl_vector *d; /* steepest descent step, size p */
gsl_vector *workp; /* workspace, length p */
gsl_vector *workn; /* workspace, length n */
double norm_g; /* || g~ || */
double cgtol; /* tolerance for CG solution */
size_t cgmaxit; /* maximum CG iterations */
} cgst_state_t;
#include "common.c"
static void * cgst_alloc (const void * params, const size_t n, const size_t p);
static void cgst_free(void *vstate);
static int cgst_init(const void *vtrust_state, void *vstate);
static int cgst_preloop(const void * vtrust_state, void * vstate);
static int cgst_step(const void * vtrust_state, const double delta,
gsl_vector * dx, void * vstate);
static int cgst_preduction(const void * vtrust_state, const gsl_vector * dx,
double * pred, void * vstate);
static double cgst_calc_tau(const gsl_vector * p, const gsl_vector * d,
const double delta);
static void *
cgst_alloc (const void * params, const size_t n, const size_t p)
{
const gsl_multilarge_nlinear_parameters *par = (const gsl_multilarge_nlinear_parameters *) params;
cgst_state_t *state;
state = calloc(1, sizeof(cgst_state_t));
if (state == NULL)
{
GSL_ERROR_NULL ("failed to allocate st state", GSL_ENOMEM);
}
state->z = gsl_vector_alloc(p);
if (state->z == NULL)
{
GSL_ERROR_NULL ("failed to allocate space for z", GSL_ENOMEM);
}
state->r = gsl_vector_alloc(p);
if (state->r == NULL)
{
GSL_ERROR_NULL ("failed to allocate space for r", GSL_ENOMEM);
}
state->d = gsl_vector_alloc(p);
if (state->d == NULL)
{
GSL_ERROR_NULL ("failed to allocate space for d", GSL_ENOMEM);
}
state->workp = gsl_vector_alloc(p);
if (state->workp == NULL)
{
GSL_ERROR_NULL ("failed to allocate space for workp", GSL_ENOMEM);
}
state->workn = gsl_vector_alloc(n);
if (state->workn == NULL)
{
GSL_ERROR_NULL ("failed to allocate space for workn", GSL_ENOMEM);
}
state->n = n;
state->p = p;
state->cgmaxit = par->max_iter;
if (state->cgmaxit == 0)
state->cgmaxit = n;
state->cgtol = par->tol;
return state;
}
static void
cgst_free(void *vstate)
{
cgst_state_t *state = (cgst_state_t *) vstate;
if (state->z)
gsl_vector_free(state->z);
if (state->r)
gsl_vector_free(state->r);
if (state->d)
gsl_vector_free(state->d);
if (state->workp)
gsl_vector_free(state->workp);
if (state->workn)
gsl_vector_free(state->workn);
free(state);
}
/*
cgst_init()
Initialize cgst solver
Inputs: vtrust_state - trust state
vstate - workspace
Return: success/error
*/
static int
cgst_init(const void *vtrust_state, void *vstate)
{
/* nothing to do */
(void)vtrust_state;
(void)vstate;
return GSL_SUCCESS;
}
static int
cgst_preloop(const void * vtrust_state, void * vstate)
{
/* nothing to do */
(void)vtrust_state;
(void)vstate;
return GSL_SUCCESS;
}
/*
cgst_step()
Calculate a new step vector
Return:
GSL_SUCCESS if CG solution found
GSL_EMAXITER if no solution found
*/
static int
cgst_step(const void * vtrust_state, const double delta,
gsl_vector * dx, void * vstate)
{
int status;
const gsl_multilarge_nlinear_trust_state *trust_state =
(const gsl_multilarge_nlinear_trust_state *) vtrust_state;
cgst_state_t *state = (cgst_state_t *) vstate;
const gsl_vector * x = trust_state->x;
const gsl_vector * f = trust_state->f;
const gsl_vector * swts = trust_state->sqrt_wts;
const gsl_vector * diag = trust_state->diag;
const gsl_multilarge_nlinear_parameters * params = trust_state->params;
gsl_multilarge_nlinear_fdf * fdf = trust_state->fdf;
double alpha, beta, u;
double norm_Jd; /* || J D^{-1} d_i || */
double norm_r; /* || r_i || */
double norm_rp1; /* || r_{i+1} || */
size_t i;
/* Step 1 of [1], section 2; scale gradient as
*
* g~ = D^{-1} g
*
* for better numerical stability
*/
for (i = 0; i < state->p; ++i)
{
double gi = gsl_vector_get(trust_state->g, i);
double di = gsl_vector_get(trust_state->diag, i);
gsl_vector_set(state->z, i, 0.0);
gsl_vector_set(state->r, i, -gi / di);
gsl_vector_set(state->d, i, -gi / di);
gsl_vector_set(state->workp, i, gi / di);
}
/* compute || g~ || */
state->norm_g = gsl_blas_dnrm2(state->workp);
for (i = 0; i < state->cgmaxit; ++i)
{
/* workp := D^{-1} d_i */
gsl_vector_memcpy(state->workp, state->d);
gsl_vector_div(state->workp, trust_state->diag);
/* workn := J D^{-1} d_i */
status = gsl_multilarge_nlinear_eval_df(CblasNoTrans, x, f, state->workp,
swts, params->h_df, params->fdtype,
fdf, state->workn, NULL, NULL);
if (status)
return status;
/* compute || J D^{-1} d_i || */
norm_Jd = gsl_blas_dnrm2(state->workn);
/* Step 2 of [1], section 2 */
if (norm_Jd == 0.0)
{
double tau = cgst_calc_tau(state->z, state->d, delta);
/* dx = z_i + tau*d_i */
scaled_addition(1.0, state->z, tau, state->d, dx);
gsl_vector_div(dx, diag);
return GSL_SUCCESS;
}
/* Step 3 of [1], section 2 */
norm_r = gsl_blas_dnrm2(state->r);
u = norm_r / norm_Jd;
alpha = u * u;
/* workp <= z_{i+1} = z_i + alpha_i*d_i */
scaled_addition(1.0, state->z, alpha, state->d, state->workp);
u = gsl_blas_dnrm2(state->workp);
if (u >= delta)
{
double tau = cgst_calc_tau(state->z, state->d, delta);
/* dx = z_i + tau*d_i */
scaled_addition(1.0, state->z, tau, state->d, dx);
gsl_vector_div(dx, diag);
return GSL_SUCCESS;
}
/* store z_{i+1} */
gsl_vector_memcpy(state->z, state->workp);
/* Step 4 of [1], section 2 */
/* compute: workp := alpha B d_i = alpha D^{-1} J^T J D^{-1} d_i,
* where J D^{-1} d_i is already stored in workn */
status = gsl_multilarge_nlinear_eval_df(CblasTrans, x, f, state->workn,
swts, params->h_df, params->fdtype,
fdf, state->workp, NULL, NULL);
if (status)
return status;
gsl_vector_div(state->workp, trust_state->diag);
gsl_vector_scale(state->workp, alpha);
/* r_{i+1} = r_i - alpha*B*d_i */
gsl_vector_sub(state->r, state->workp);
norm_rp1 = gsl_blas_dnrm2(state->r);
u = norm_rp1 / state->norm_g;
if (u < state->cgtol)
{
gsl_vector_memcpy(dx, state->z);
gsl_vector_div(dx, diag);
return GSL_SUCCESS;
}
/* Step 5 of [1], section 2 */
/* compute u = ||r_{i+1}|| / || r_i|| */
u = norm_rp1 / norm_r;
beta = u * u;
/* compute: d_{i+1} = rt_{i+1} + beta*d_i */
scaled_addition(1.0, state->r, beta, state->d, state->d);
}
/* failed to converge, return current estimate */
gsl_vector_memcpy(dx, state->z);
gsl_vector_div(dx, diag);
return GSL_EMAXITER;
}
static int
cgst_preduction(const void * vtrust_state, const gsl_vector * dx,
double * pred, void * vstate)
{
const gsl_multilarge_nlinear_trust_state *trust_state =
(const gsl_multilarge_nlinear_trust_state *) vtrust_state;
cgst_state_t *state = (cgst_state_t *) vstate;
*pred = quadratic_preduction(trust_state, dx, state->workn);
return GSL_SUCCESS;
}
/*
cgst_calc_tau()
Compute tau > 0 such that:
|| p + tau*d || = delta
*/
static double
cgst_calc_tau(const gsl_vector * p, const gsl_vector * d,
const double delta)
{
double norm_p, norm_d, u;
double t1, t2, tau;
norm_p = gsl_blas_dnrm2(p);
norm_d = gsl_blas_dnrm2(d);
/* compute (p, d) */
gsl_blas_ddot(p, d, &u);
t1 = u / (norm_d * norm_d);
t2 = t1*u + (delta + norm_p) * (delta - norm_p);
tau = -t1 + sqrt(t2) / norm_d;
return tau;
}
static const gsl_multilarge_nlinear_trs cgst_type =
{
"steihaug-toint",
cgst_alloc,
cgst_init,
cgst_preloop,
cgst_step,
cgst_preduction,
cgst_free
};
const gsl_multilarge_nlinear_trs *gsl_multilarge_nlinear_trs_cgst = &cgst_type;
| {
"alphanum_fraction": 0.6194492922,
"avg_line_length": 26.9295039164,
"ext": "c",
"hexsha": "9e86cdc27301e0430dc4a86c3ef2df78d4d87ae9",
"lang": "C",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-14T12:31:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-20T16:22:57.000Z",
"max_forks_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Brian-ning/HMNE",
"max_forks_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/multilarge_nlinear/cgst.c",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "1b4ee4c146f526ea6e2f4f8607df7e9687204a9e",
"max_issues_repo_issues_event_max_datetime": "2019-12-22T00:00:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-12-16T17:41:24.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "Brian-ning/HMNE",
"max_issues_repo_path": "Source/BaselineMethods/MNE/C++/gsl-2.4/multilarge_nlinear/cgst.c",
"max_line_length": 100,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ielomariala/Hex-Game",
"max_stars_repo_path": "gsl-2.6/multilarge_nlinear/cgst.c",
"max_stars_repo_stars_event_max_datetime": "2021-06-14T11:51:37.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-14T11:51:37.000Z",
"num_tokens": 2942,
"size": 10314
} |
#include <vector>
#include <fstream>
#include <cmath>
#include <cblas.h>
#include <fftw3.h>
#include <sys/time.h>
#include <time.h>
using namespace std;
class CochlearModel_1D{
private:
int N;
double Lb;
double L;
double W;
double H;
double rho;
double dx;
vector<double> x;
vector<double> ch_damp;
vector<double> k1;
double m1;
vector<double> c1;
vector<double> k2;
double m2;
vector<double> c2;
vector<double> k3;
vector<double> c3;
vector<double> k4;
vector<double> c4;
vector<double> k1k3;
vector<double> c1c3;
vector<double> k2k3;
vector<double> c2c3;
double g;
double b;
vector<double> gamma;
double dt;
double beta;
vector<double> Gohc(vector<double> uc);
vector<double> dGohc(vector<double> uc, vector<double> vc);
void get_g(vector<double> vb, vector<double> ub, vector<double> vt, vector<double> ut, vector<double>& gb, vector<double>& gt);
public:
CochlearModel_1D(int num_segment, vector<double> gamma_given)
{
N = num_segment;
Lb = 3.5;
L = 0.1;
W = 0.1;
H = 0.1;
rho = 1.0;
dx = Lb/N;
m1 = 3e-3;
m2 = 0.5e-3;
for (int ii = 0; ii < N; ii++){
x.push_back(dx * ii);
// ch_damp.push_back(2.8 * exp(-0.1*x[ii]));
ch_damp.push_back(1.0);
k1.push_back(2.2e8 * exp(-3 * x[ii]));
c1.push_back(6 + 670 * exp(-1.5 * x[ii]) * ch_damp[ii]);
k2.push_back(1.4e6 * exp(-3.3 * x[ii]));
c2.push_back(4.4 * exp(-1.65 * x[ii]) * ch_damp[ii]);
k3.push_back(2.0e6 * exp(-3 * x[ii]));
c3.push_back(0.8 * exp(-0.6 * x[ii]) * ch_damp[ii]);
k4.push_back(1.15e8 * exp(-3 * x[ii]));
c4.push_back(440.0 * exp(-1.5 * x[ii]) * ch_damp[ii]);
k1k3.push_back(k1[ii] + k3[ii]);
c1c3.push_back(c1[ii] + c3[ii]);
k2k3.push_back(k2[ii] + k3[ii]);
c2c3.push_back(c2[ii] + c3[ii]);
gamma.push_back(gamma_given[ii]);
}
g = 1;
b = 0.4;
dt = 10e-6;
beta = 50e-7;
}
void solve_time_domain(vector<double> f, vector<vector<double> >& mat_vb, vector<vector<double> >& mat_ub, vector<vector<double> >& mat_p);
}; | {
"alphanum_fraction": 0.5349531117,
"avg_line_length": 25.5,
"ext": "h",
"hexsha": "d43435ded6ac56cb12ccac80da4415117b2c2f6e",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-12-01T12:10:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-12-01T12:10:18.000Z",
"max_forks_repo_head_hexsha": "8f430f461e633b18d36134644baa7631b3853f26",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "y-muraka/Human-Cochlear-Model",
"max_forks_repo_path": "cpp/fft/CochlearModel_1D_fft.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8f430f461e633b18d36134644baa7631b3853f26",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "y-muraka/Human-Cochlear-Model",
"max_issues_repo_path": "cpp/fft/CochlearModel_1D_fft.h",
"max_line_length": 142,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8f430f461e633b18d36134644baa7631b3853f26",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "y-muraka/Human-Cochlear-Model",
"max_stars_repo_path": "cpp/fft/CochlearModel_1D_fft.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 757,
"size": 2346
} |
/*
FRACTAL - A program growing fractals to benchmark parallelization and drawing
libraries.
Copyright 2009-2021, Javier Burguete Tolosa.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY Javier Burguete Tolosa ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL Javier Burguete Tolosa OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* \file draw.c
* \brief Source file to define the drawing data and functions.
* \author Javier Burguete Tolosa.
* \copyright Copyright 2009-2021, Javier Burguete Tolosa.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include <glib.h>
#include <png.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include <gtk/gtk.h>
#include <GL/glew.h>
#if HAVE_FREEGLUT
#include <GL/freeglut.h>
#elif HAVE_SDL
#include <SDL.h>
#elif HAVE_GLFW
#include <GLFW/glfw3.h>
#endif
#include "config.h"
#include "fractal.h"
#include "image.h"
#include "text.h"
#include "graphic.h"
#include "draw.h"
#include "simulator.h"
Graphic graphic[1]; ///< Graphic data.
/**
* Function to resize the draw.
*/
void
draw_resize (int w, ///< Graphic window width.
int h) ///< Graphic window height.
{
#if DEBUG
printf ("draw_resize: start\n");
fflush (stdout);
#endif
if ((unsigned int) w < width)
w = width;
if ((unsigned int) h < height)
h = height;
#if HAVE_FREEGLUT
glutReshapeWindow (w, h);
#endif
window_width = w;
window_height = h;
glViewport (0, 0, w, h);
#if DEBUG
printf ("draw_resize: end\n");
fflush (stdout);
#endif
}
#if HAVE_GTKGLAREA
void
resize (GtkGLArea * gl_area __attribute__((unused)), int w, int h)
{
draw_resize (w, h);
}
#endif
/**
* Function to render graphics.
*/
void
draw ()
{
#if HAVE_GLFW
int graphic_width, graphic_height;
#endif
#if DEBUG
printf ("draw: start\n");
fflush (stdout);
#endif
#if HAVE_GLFW
glfwGetFramebufferSize (window, &graphic_width, &graphic_height);
draw_resize (graphic_width, graphic_height);
#endif
graphic_render (graphic);
// Displaying the draw
#if HAVE_GTKGLAREA
gtk_widget_queue_draw (GTK_WIDGET (dialog_simulator->gl_area));
#elif HAVE_FREEGLUT
glutSwapBuffers ();
#elif HAVE_SDL
SDL_GL_SwapWindow (window);
#elif HAVE_GLFW
glfwSwapBuffers (window);
#endif
#if DEBUG
printf ("draw: end\n");
fflush (stdout);
#endif
}
| {
"alphanum_fraction": 0.7314436002,
"avg_line_length": 24.7971014493,
"ext": "c",
"hexsha": "9e34df5e5503891a0786ae058c697a9365783940",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "95d711dcb7b385556fb77794bc01737b21e99774",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "jburguete/fractal",
"max_forks_repo_path": "3.4.15/draw.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "95d711dcb7b385556fb77794bc01737b21e99774",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "jburguete/fractal",
"max_issues_repo_path": "3.4.15/draw.c",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "95d711dcb7b385556fb77794bc01737b21e99774",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "jburguete/fractal",
"max_stars_repo_path": "3.4.15/draw.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 846,
"size": 3422
} |
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#include <gbpLib.h>
#include <gbpMath.h>
#include <gbpCosmo_mass_functions.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_spline.h>
// Compute comoving mass function
double mass_function(double M_interp, double z, cosmo_info **cosmo, int mode, ...) {
va_list vargs;
va_start(vargs, mode);
// Get passed parameters (if mode specifies they are there).
double *P = NULL;
if(SID_CHECK_BITFIELD_SWITCH(mode, MF_PASS_PARAMS))
P = (double *)va_arg(vargs, double *);
// Initialize/compute some misc. cosmology things
double sigma_interp = sqrt(power_spectrum_variance(k_of_M(M_interp, *cosmo), z, cosmo, PSPEC_LINEAR_TF, PSPEC_ALL_MATTER));
double Omega_M = ((double *)ADaPS_fetch(*cosmo, "Omega_M"))[0];
double rho_o = Omega_M * rho_crit_z(0, *cosmo);
// Compute mass function (eqn 41 of Lukic et al, 2007, for example)
double dlnInvs_dlogM = dln_Inv_sigma_dlogM(cosmo, M_interp, PSPEC_LINEAR_TF, PSPEC_ALL_MATTER);
double rval = rho_o * scaled_mass_function(sigma_interp, mode, P) * dlnInvs_dlogM / M_interp;
va_end(vargs);
return (rval);
}
| {
"alphanum_fraction": 0.7020242915,
"avg_line_length": 37.4242424242,
"ext": "c",
"hexsha": "4d7adc95adc2464b3a7493b39167b7049251a2b1",
"lang": "C",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-01T08:14:24.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-23T00:50:40.000Z",
"max_forks_repo_head_hexsha": "5157d2e377edbd4806258d1c16b329373186d43a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "gbpoole/gbpCode",
"max_forks_repo_path": "src/gbpAstro/gbpCosmo/mass_functions/mass_function.c",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "5157d2e377edbd4806258d1c16b329373186d43a",
"max_issues_repo_issues_event_max_datetime": "2019-06-18T00:40:46.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-07-30T11:10:49.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "gbpoole/gbpCode",
"max_issues_repo_path": "src/gbpAstro/gbpCosmo/mass_functions/mass_function.c",
"max_line_length": 127,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "5157d2e377edbd4806258d1c16b329373186d43a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "gbpoole/gbpCode",
"max_stars_repo_path": "src/gbpAstro/gbpCosmo/mass_functions/mass_function.c",
"max_stars_repo_stars_event_max_datetime": "2015-10-20T11:39:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-10-20T11:39:53.000Z",
"num_tokens": 355,
"size": 1235
} |
/*
Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The OpenAirInterface Software Alliance licenses this file to You under
the OAI Public License, Version 1.1 (the "License"); you may not use this file
except in compliance with the License.
You may obtain a copy of the License at
http://www.openairinterface.org/?page_id=698
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-------------------------------------------------------------------------------
For more information about the OpenAirInterface (OAI) Software Alliance:
contact@openairinterface.org
*/
/*! \file PHY/LTE_TRANSPORT/dlsch_demodulation.c
\brief Top-level routines for demodulating the PDSCH physical channel from 36-211, V8.6 2009-03
\author R. Knopp, F. Kaltenberger,A. Bhamri, S. Aubert, X. Xiang
\date 2011
\version 0.1
\company Eurecom
\email: knopp@eurecom.fr,florian.kaltenberger@eurecom.fr,ankit.bhamri@eurecom.fr,sebastien.aubert@eurecom.fr
\note
\warning
*/
#include "PHY/defs_UE.h"
#include "PHY/phy_extern_ue.h"
#include "SCHED_UE/sched_UE.h"
#include "transport_ue.h"
#include "transport_proto_ue.h"
#include "PHY/sse_intrin.h"
#include "T.h"
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <string.h>
#include <linux/version.h>
#if RHEL_RELEASE_CODE >= 1796
#include <lapacke/lapacke_utils.h>
#include <lapacke/lapacke.h>
#else
#include <lapacke_utils.h>
#include <lapacke.h>
#endif
#include <cblas.h>
#include "linear_preprocessing_rec.h"
#define NOCYGWIN_STATIC
//#define DEBUG_MMSE
/* dynamic shift for LLR computation for TM3/4
set as command line argument, see lte-softmodem.c
default value: 0
*/
int16_t dlsch_demod_shift = 0;
int16_t interf_unaw_shift = 13;
unsigned char offset_mumimo_llr_drange_fix = 0;
//inferference-free case
unsigned char interf_unaw_shift_tm4_mcs[29] = {5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0,
1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0
} ;
unsigned char interf_unaw_shift_tm1_mcs[29] = {5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1,
0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6
} ; // mcs 21, 26, 28 seem to be errorneous
/*
//original values from sebastion + same hand tuning
unsigned char offset_mumimo_llr_drange[29][3]={{8,8,8},{7,7,7},{7,7,7},{7,7,7},{6,6,6},{6,6,6},{6,6,6},{5,5,5},{4,4,4},{1,2,4}, // QPSK
{5,5,4},{5,5,5},{5,5,5},{3,3,3},{2,2,2},{2,2,2},{2,2,2}, // 16-QAM
{2,2,1},{3,3,3},{3,3,3},{3,3,1},{2,2,2},{2,2,2},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}; //64-QAM
*/
/*
//first optimization try
unsigned char offset_mumimo_llr_drange[29][3]={{7, 8, 7},{6, 6, 7},{6, 6, 7},{6, 6, 6},{5, 6, 6},{5, 5, 6},{5, 5, 6},{4, 5, 4},{4, 3, 4},{3, 2, 2},{6, 5, 5},{5, 4, 4},{5, 5, 4},{3, 3, 2},{2, 2, 1},{2, 1, 1},{2, 2, 2},{3, 3, 3},{3, 3, 2},{3, 3, 2},{3, 2, 1},{2, 2, 2},{2, 2, 2},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}};
*/
//second optimization try
/*
unsigned char offset_mumimo_llr_drange[29][3]={{5, 8, 7},{4, 6, 8},{3, 6, 7},{7, 7, 6},{4, 7, 8},{4, 7, 4},{6, 6, 6},{3, 6, 6},{3, 6, 6},{1, 3, 4},{1, 1, 0},{3, 3, 2},{3, 4, 1},{4, 0, 1},{4, 2, 2},{3, 1, 2},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}}; w
*/
unsigned char offset_mumimo_llr_drange[29][3] = {{0, 6, 5}, {0, 4, 5}, {0, 4, 5}, {0, 5, 4}, {0, 5, 6}, {0, 5, 3}, {0, 4, 4}, {0, 4, 4}, {0, 3, 3}, {0, 1, 2}, {1, 1, 0}, {1, 3, 2}, {3, 4, 1}, {2, 0, 0}, {2, 2, 2}, {1, 1, 1}, {2, 1, 0}, {2, 1, 1}, {1, 0, 1}, {1, 0, 1}, {0, 0, 0}, {1, 0, 0}, {0, 0, 0}, {0, 1, 0}, {1, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 0}};
extern void print_shorts(char *s, int16_t *x);
int rx_pdsch(PHY_VARS_UE *ue,
PDSCH_t type,
unsigned char eNB_id,
unsigned char eNB_id_i, //if this == ue->n_connected_eNB, we assume MU interference
uint32_t frame,
uint8_t subframe,
unsigned char symbol,
unsigned char first_symbol_flag,
RX_type_t rx_type,
unsigned char i_mod,
unsigned char harq_pid)
{
LTE_UE_COMMON *common_vars = &ue->common_vars;
LTE_UE_PDSCH **pdsch_vars;
LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
PHY_MEASUREMENTS *measurements = &ue->measurements;
LTE_UE_DLSCH_t **dlsch;
int avg[4];
int avg_0[2];
int avg_1[2];
unsigned short mmse_flag = 0;
#if UE_TIMING_TRACE
uint8_t slot = 0;
#endif
unsigned char aatx, aarx;
unsigned short nb_rb = 0, round;
int avgs = 0, rb;
LTE_DL_UE_HARQ_t *dlsch0_harq, *dlsch1_harq = 0;
uint8_t beamforming_mode;
uint32_t *rballoc;
int32_t **rxdataF_comp_ptr;
int32_t **dl_ch_mag_ptr;
int32_t codeword_TB0 = -1;
int32_t codeword_TB1 = -1;
switch(type)
{
case SI_PDSCH:
pdsch_vars = &ue->pdsch_vars_SI[eNB_id];
dlsch = &ue->dlsch_SI[eNB_id];
dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
beamforming_mode = 0;
break;
case RA_PDSCH:
pdsch_vars = &ue->pdsch_vars_ra[eNB_id];
dlsch = &ue->dlsch_ra[eNB_id];
dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
beamforming_mode = 0;
break;
case PDSCH:
pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]];
dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id];
//printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status);
LOG_D(PHY, "AbsSubframe %d.%d / Sym %d harq_pid %d, harq status %d.%d \n",
frame, subframe, symbol, harq_pid,
dlsch[0]->harq_processes[harq_pid]->status,
dlsch[1]->harq_processes[harq_pid]->status);
if((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
(dlsch[1]->harq_processes[harq_pid]->status == ACTIVE))
{
codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
dlsch0_harq = dlsch[codeword_TB0]->harq_processes[harq_pid];
dlsch1_harq = dlsch[codeword_TB1]->harq_processes[harq_pid];
#ifdef DEBUG_HARQ
printf("[DEMOD] I am assuming both TBs are active\n");
#endif
}
else if((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) &&
(dlsch[1]->harq_processes[harq_pid]->status != ACTIVE))
{
codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword;
dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
dlsch1_harq = NULL;
codeword_TB1 = -1;
#ifdef DEBUG_HARQ
printf("[DEMOD] I am assuming only TB0 is active\n");
#endif
}
else if((dlsch[0]->harq_processes[harq_pid]->status != ACTIVE) &&
(dlsch[1]->harq_processes[harq_pid]->status == ACTIVE))
{
codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword;
dlsch0_harq = dlsch[1]->harq_processes[harq_pid];
dlsch1_harq = NULL;
codeword_TB0 = -1;
#ifdef DEBUG_HARQ
printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword);
#endif
}
else
{
LOG_E(PHY, "[UE][FATAL] Frame %d subframe %d: no active DLSCH\n", ue->proc.proc_rxtx[0].frame_rx, subframe);
return(-1);
}
beamforming_mode = ue->transmission_mode[eNB_id] < 7 ? 0 : ue->transmission_mode[eNB_id];
break;
default:
LOG_E(PHY, "[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n", ue->proc.proc_rxtx[0].frame_rx, subframe, type);
return(-1);
break;
}
#ifdef DEBUG_HARQ
printf("[DEMOD] MIMO mode = %d\n", dlsch0_harq->mimo_mode);
printf("[DEMOD] cw for TB0 = %d, cw for TB1 = %d\n", codeword_TB0, codeword_TB1);
#endif
DevAssert(dlsch0_harq);
round = dlsch0_harq->round;
//printf("round = %d\n", round);
if(eNB_id > 2)
{
LOG_W(PHY, "dlsch_demodulation.c: Illegal eNB_id %d\n", eNB_id);
return(-1);
}
if(!common_vars)
{
LOG_W(PHY, "dlsch_demodulation.c: Null common_vars\n");
return(-1);
}
if(!dlsch[0])
{
LOG_W(PHY, "dlsch_demodulation.c: Null dlsch_ue pointer\n");
return(-1);
}
if(!pdsch_vars)
{
LOG_W(PHY, "dlsch_demodulation.c: Null pdsch_vars pointer\n");
return(-1);
}
if(!frame_parms)
{
LOG_W(PHY, "dlsch_demodulation.c: Null frame_parms\n");
return(-1);
}
if(((frame_parms->Ncp == NORMAL) && (symbol >= 7)) ||
((frame_parms->Ncp == EXTENDED) && (symbol >= 6)))
{
rballoc = dlsch0_harq->rb_alloc_odd;
}
else
{
rballoc = dlsch0_harq->rb_alloc_even;
}
if(dlsch0_harq->mimo_mode > DUALSTREAM_PUSCH_PRECODING)
{
LOG_E(PHY, "This transmission mode is not yet supported!\n");
return(-1);
}
if((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >= DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode <= DUALSTREAM_PUSCH_PRECODING)))
{
DevAssert(dlsch1_harq);
if(eNB_id != eNB_id_i)
{
LOG_E(PHY, "TM3/TM4 requires to set eNB_id==eNB_id_i!\n");
return(-1);
}
}
#if UE_TIMING_TRACE
if(symbol > ue->frame_parms.symbols_per_tti >> 1)
{
slot = 1;
}
#endif
#ifdef DEBUG_HARQ
printf("Demod dlsch0_harq->pmi_alloc %d\n", dlsch0_harq->pmi_alloc);
#endif
if(frame_parms->nb_antenna_ports_eNB > 1 && beamforming_mode == 0)
{
#ifdef DEBUG_DLSCH_MOD
LOG_D(PHY, "dlsch: using pmi %x (%p), rb_alloc %x\n", pmi2hex_2Ar1(dlsch0_harq->pmi_alloc), dlsch[0], dlsch0_harq->rb_alloc_even[0]);
#endif
#if UE_TIMING_TRACE
start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
#endif
nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id],
pdsch_vars[eNB_id]->rxdataF_ext,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
dlsch0_harq->pmi_alloc,
pdsch_vars[eNB_id]->pmi_ext,
rballoc,
symbol,
subframe,
ue->high_speed_flag,
frame_parms,
dlsch0_harq->mimo_mode);
#ifdef DEBUG_DLSCH_MOD
printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ", pmi2hex_2Ar1(dlsch0_harq->pmi_alloc), *rballoc);
for(rb = 0; rb < nb_rb; rb++)
{
printf("%d", pdsch_vars[eNB_id]->pmi_ext[rb]);
}
printf("\n");
#endif
if(rx_type >= rx_IC_single_stream)
{
if(eNB_id_i < ue->n_connected_eNB) // we are in TM5
nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id_i],
pdsch_vars[eNB_id_i]->rxdataF_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
dlsch0_harq->pmi_alloc,
pdsch_vars[eNB_id_i]->pmi_ext,
rballoc,
symbol,
subframe,
ue->high_speed_flag,
frame_parms,
dlsch0_harq->mimo_mode);
else
nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id],
pdsch_vars[eNB_id_i]->rxdataF_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
dlsch0_harq->pmi_alloc,
pdsch_vars[eNB_id_i]->pmi_ext,
rballoc,
symbol,
subframe,
ue->high_speed_flag,
frame_parms,
dlsch0_harq->mimo_mode);
}
}
else if(beamforming_mode == 0) //else if nb_antennas_ports_eNB==1 && beamforming_mode == 0
{
nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id],
pdsch_vars[eNB_id]->rxdataF_ext,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
dlsch0_harq->pmi_alloc,
pdsch_vars[eNB_id]->pmi_ext,
rballoc,
symbol,
subframe,
ue->high_speed_flag,
frame_parms);
if(rx_type == rx_IC_single_stream)
{
if(eNB_id_i < ue->n_connected_eNB)
nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id_i],
pdsch_vars[eNB_id_i]->rxdataF_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
dlsch0_harq->pmi_alloc,
pdsch_vars[eNB_id_i]->pmi_ext,
rballoc,
symbol,
subframe,
ue->high_speed_flag,
frame_parms);
else
nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id],
pdsch_vars[eNB_id_i]->rxdataF_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
dlsch0_harq->pmi_alloc,
pdsch_vars[eNB_id_i]->pmi_ext,
rballoc,
symbol,
subframe,
ue->high_speed_flag,
frame_parms);
}
}
else if(beamforming_mode == 7) //else if beamforming_mode == 7
{
nb_rb = dlsch_extract_rbs_TM7(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF,
pdsch_vars[eNB_id]->dl_bf_ch_estimates,
pdsch_vars[eNB_id]->rxdataF_ext,
pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
rballoc,
symbol,
subframe,
ue->high_speed_flag,
frame_parms);
}
else if(beamforming_mode > 7)
{
LOG_W(PHY, "dlsch_demodulation: beamforming mode not supported yet.\n");
}
//printf("nb_rb = %d, eNB_id %d\n",nb_rb,eNB_id);
if(nb_rb == 0)
{
// LOG_D(PHY,"dlsch_demodulation.c: nb_rb=0\n");
return(-1);
}
#if UE_TIMING_TRACE
stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n", frame, subframe, slot, symbol,
ue->high_speed_flag, type, ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time / (cpuf * 1000.0));
#endif
#if UE_TIMING_TRACE
start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
#endif
aatx = frame_parms->nb_antenna_ports_eNB;
aarx = frame_parms->nb_antennas_rx;
dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
frame_parms,
dlsch,
symbol,
nb_rb);
if((dlsch0_harq->mimo_mode < DUALSTREAM_UNIFORM_PRECODING1) &&
(rx_type == rx_IC_single_stream) &&
(eNB_id_i == ue->n_connected_eNB) &&
(dlsch0_harq->dl_power_off == 0)
) // TM5 two-user
{
dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
frame_parms,
dlsch,
symbol,
nb_rb);
}
#if UE_TIMING_TRACE
stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n", frame, subframe, slot, symbol, ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time / (cpuf * 1000.0));
start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
#endif
if(first_symbol_flag == 1)
{
if(beamforming_mode == 0)
{
if(dlsch0_harq->mimo_mode < LARGE_CDD)
{
dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
frame_parms,
avg,
symbol,
nb_rb);
avgs = 0;
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
avgs = cmax(avgs, avg[(aatx << 1) + aarx]);
}
pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs) / 2) + 1;
}
else if((dlsch0_harq->mimo_mode == LARGE_CDD) ||
((dlsch0_harq->mimo_mode >= DUALSTREAM_UNIFORM_PRECODING1) &&
(dlsch0_harq->mimo_mode <= DUALSTREAM_PUSCH_PRECODING)))
{
dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
frame_parms,
pdsch_vars[eNB_id]->pmi_ext,
avg_0,
avg_1,
symbol,
nb_rb,
mmse_flag,
dlsch0_harq->mimo_mode);
LOG_D(PHY, "Channel Level TM34 avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0],
avg_1[0], rx_type, rx_standard, dlsch_demod_shift);
if(rx_type > rx_standard)
{
avg_0[0] = (log2_approx(avg_0[0]) / 2) + dlsch_demod_shift; // + 2 ;//+ 4;
avg_1[0] = (log2_approx(avg_1[0]) / 2) + dlsch_demod_shift; // + 2 ;//+ 4;
pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0], 0);
pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0], 0);
// printf("dlsch_demod_shift %d\n", dlsch_demod_shift);
}
else
{
avg_0[0] = (log2_approx(avg_0[0]) / 2) - 13 + interf_unaw_shift;
avg_1[0] = (log2_approx(avg_1[0]) / 2) - 13 + interf_unaw_shift;
pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0], 0);
pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0], 0);
}
}
else if(dlsch0_harq->mimo_mode < DUALSTREAM_UNIFORM_PRECODING1) // single-layer precoding (TM5, TM6)
{
if((rx_type == rx_IC_single_stream) && (eNB_id_i == ue->n_connected_eNB) && (dlsch0_harq->dl_power_off == 0))
{
dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
frame_parms,
pdsch_vars[eNB_id]->pmi_ext,
avg,
symbol,
nb_rb);
avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod >> 1) - 1];
pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0], 0);
}
else if(dlsch0_harq->dl_power_off == 1) //TM6
{
dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
frame_parms,
avg,
symbol,
nb_rb);
avgs = 0;
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
avgs = cmax(avgs, avg[(aatx << 1) + aarx]);
}
pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs) / 2) + 1;
pdsch_vars[eNB_id]->log2_maxh++;
}
}
}
else if(beamforming_mode == 7)
dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
frame_parms,
avg,
symbol,
nb_rb);
#ifdef UE_DEBUG_TRACE
LOG_D(PHY, "[DLSCH] AbsSubframe %d.%d log2_maxh = %d [log2_maxh0 %d log2_maxh1 %d] (%d,%d)\n",
frame % 1024, subframe, pdsch_vars[eNB_id]->log2_maxh,
pdsch_vars[eNB_id]->log2_maxh0,
pdsch_vars[eNB_id]->log2_maxh1,
avg[0], avgs);
//LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode);
#endif
//wait until pdcch is decoded
//proc->channel_level = 1;
}
/*
uint32_t wait = 0;
while(proc->channel_level == 0)
{
usleep(1);
wait++;
}
*/
#if T_TRACER
if(type == PDSCH)
{
T(T_UE_PHY_PDSCH_ENERGY, T_INT(eNB_id), T_INT(frame % 1024), T_INT(subframe),
T_INT(avg[0]), T_INT(avg[1]), T_INT(avg[2]), T_INT(avg[3]));
}
#endif
#if UE_TIMING_TRACE
stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n", frame, subframe, slot, symbol, first_symbol_flag,
ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time / (cpuf * 1000.0));
start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
#endif
if(rx_type == rx_IC_dual_stream && mmse_flag == 1)
{
precode_channel_est(pdsch_vars[eNB_id]->dl_ch_estimates_ext,
frame_parms,
pdsch_vars[eNB_id],
symbol,
nb_rb,
dlsch0_harq->mimo_mode);
mmse_processing_oai(pdsch_vars[eNB_id],
frame_parms,
measurements,
first_symbol_flag,
dlsch0_harq->mimo_mode,
mmse_flag,
0.0,
symbol,
nb_rb);
}
// Now channel compensation
if(dlsch0_harq->mimo_mode < LARGE_CDD)
{
dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
pdsch_vars[eNB_id]->rxdataF_comp0,
(aatx > 1) ? pdsch_vars[eNB_id]->rho : NULL,
frame_parms,
symbol,
first_symbol_flag,
dlsch0_harq->Qm,
nb_rb,
pdsch_vars[eNB_id]->log2_maxh,
measurements); // log2_maxh+I0_shift
if(symbol == 5)
{
LOG_M("rxF_comp_d.m", "rxF_c_d", &pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1);
}
if((rx_type == rx_IC_single_stream) &&
(eNB_id_i < ue->n_connected_eNB))
{
dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
pdsch_vars[eNB_id_i]->dl_ch_mag0,
pdsch_vars[eNB_id_i]->dl_ch_magb0,
pdsch_vars[eNB_id_i]->rxdataF_comp0,
(aatx > 1) ? pdsch_vars[eNB_id_i]->rho : NULL,
frame_parms,
symbol,
first_symbol_flag,
i_mod,
nb_rb,
pdsch_vars[eNB_id]->log2_maxh,
measurements); // log2_maxh+I0_shift
if(symbol == 5)
{
LOG_M("rxF_comp_d.m", "rxF_c_d", &pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1);
LOG_M("rxF_comp_i.m", "rxF_c_i", &pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1);
}
dlsch_dual_stream_correlation(frame_parms,
symbol,
nb_rb,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->log2_maxh);
}
}
else if((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >= DUALSTREAM_UNIFORM_PRECODING1) &&
(dlsch0_harq->mimo_mode <= DUALSTREAM_PUSCH_PRECODING)))
{
dlsch_channel_compensation_TM34(frame_parms,
pdsch_vars[eNB_id],
measurements,
eNB_id,
symbol,
dlsch0_harq->Qm,
dlsch1_harq->Qm,
harq_pid,
dlsch0_harq->round,
dlsch0_harq->mimo_mode,
nb_rb,
mmse_flag,
pdsch_vars[eNB_id]->log2_maxh0,
pdsch_vars[eNB_id]->log2_maxh1);
if(symbol == 5)
{
LOG_M("rxF_comp_d00.m", "rxF_c_d00", &pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); // should be QAM
LOG_M("rxF_comp_d01.m", "rxF_c_d01", &pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); //should be almost 0
LOG_M("rxF_comp_d10.m", "rxF_c_d10", &pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); //should be almost 0
LOG_M("rxF_comp_d11.m", "rxF_c_d11", &pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); //should be QAM
}
// compute correlation between signal and interference channels (rho12 and rho21)
dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22
symbol,
nb_rb,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
&(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->log2_maxh0);
//printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] );
//to be optimized (just take complex conjugate)
dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21
symbol,
nb_rb,
&(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]),
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->log2_maxh1);
// printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext );
//printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh);
if(symbol == 5)
{
LOG_M("rho0_0.m", "rho0_0", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); // should be QAM
LOG_M("rho2_0.m", "rho2_0", &pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); //should be almost 0
LOG_M("rho0_1.m.m", "rho0_1", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][1][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); //should be almost 0
LOG_M("rho2_1.m", "rho2_1", &pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); //should be QAM
}
}
else if(dlsch0_harq->mimo_mode < DUALSTREAM_UNIFORM_PRECODING1) // single-layer precoding (TM5, TM6)
{
if((rx_type == rx_IC_single_stream) && (eNB_id_i == ue->n_connected_eNB) && (dlsch0_harq->dl_power_off == 0))
{
dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id]->pmi_ext,
frame_parms,
measurements,
eNB_id,
symbol,
dlsch0_harq->Qm,
nb_rb,
pdsch_vars[eNB_id]->log2_maxh,
dlsch0_harq->dl_power_off);
for(rb = 0; rb < nb_rb; rb++)
{
switch(pdsch_vars[eNB_id]->pmi_ext[rb])
{
case 0:
pdsch_vars[eNB_id_i]->pmi_ext[rb] = 1;
break;
case 1:
pdsch_vars[eNB_id_i]->pmi_ext[rb] = 0;
break;
case 2:
pdsch_vars[eNB_id_i]->pmi_ext[rb] = 3;
break;
case 3:
pdsch_vars[eNB_id_i]->pmi_ext[rb] = 2;
break;
}
// if (rb==0)
// printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]);
}
dlsch_channel_compensation_TM56(pdsch_vars[eNB_id_i]->rxdataF_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
pdsch_vars[eNB_id_i]->dl_ch_mag0,
pdsch_vars[eNB_id_i]->dl_ch_magb0,
pdsch_vars[eNB_id_i]->rxdataF_comp0,
pdsch_vars[eNB_id_i]->pmi_ext,
frame_parms,
measurements,
eNB_id_i,
symbol,
i_mod,
nb_rb,
pdsch_vars[eNB_id]->log2_maxh,
dlsch0_harq->dl_power_off);
if(symbol == 5)
{
LOG_M("rxF_comp_d.m", "rxF_c_d", &pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1);
LOG_M("rxF_comp_i.m", "rxF_c_i", &pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1);
}
dlsch_dual_stream_correlation(frame_parms,
symbol,
nb_rb,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
pdsch_vars[eNB_id_i]->dl_ch_estimates_ext,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->log2_maxh);
}
else if(dlsch0_harq->dl_power_off == 1)
{
dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext,
pdsch_vars[eNB_id]->dl_ch_estimates_ext,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id]->pmi_ext,
frame_parms,
measurements,
eNB_id,
symbol,
dlsch0_harq->Qm,
nb_rb,
pdsch_vars[eNB_id]->log2_maxh,
1);
}
}
else if(dlsch0_harq->mimo_mode == TM7) //TM7
{
dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext,
pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
pdsch_vars[eNB_id]->rxdataF_comp0,
(aatx > 1) ? pdsch_vars[eNB_id]->rho : NULL,
frame_parms,
symbol,
first_symbol_flag,
get_Qm(dlsch0_harq->mcs),
nb_rb,
//9,
pdsch_vars[eNB_id]->log2_maxh,
measurements); // log2_maxh+I0_shift
}
#if UE_TIMING_TRACE
stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d Channel Comp %5.2f \n", frame, subframe, slot, symbol, pdsch_vars[eNB_id]->log2_maxh,
ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time / (cpuf * 1000.0));
start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
#endif
if(frame_parms->nb_antennas_rx > 1)
{
if((dlsch0_harq->mimo_mode == LARGE_CDD) ||
((dlsch0_harq->mimo_mode >= DUALSTREAM_UNIFORM_PRECODING1) &&
(dlsch0_harq->mimo_mode <= DUALSTREAM_PUSCH_PRECODING))) // TM3 or TM4
{
if(frame_parms->nb_antenna_ports_eNB == 2)
{
dlsch_detection_mrc_TM34(frame_parms,
pdsch_vars[eNB_id],
harq_pid,
dlsch0_harq->round,
symbol,
nb_rb,
1);
if(symbol == 5)
{
LOG_M("rho0_mrc.m", "rho0_0", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); // should be QAM
LOG_M("rho2_mrc.m", "rho2_0", &pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol * frame_parms->N_RB_DL * 12], frame_parms->N_RB_DL * 12, 1, 1); //should be almost 0
}
}
}
else
{
dlsch_detection_mrc(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id_i]->rxdataF_comp0,
pdsch_vars[eNB_id]->rho,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
pdsch_vars[eNB_id_i]->dl_ch_mag0,
pdsch_vars[eNB_id_i]->dl_ch_magb0,
symbol,
nb_rb,
rx_type == rx_IC_single_stream);
}
}
// printf("Combining");
if((dlsch0_harq->mimo_mode == SISO) ||
((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) &&
(dlsch0_harq->mimo_mode <= PUSCH_PRECODING0)) ||
(dlsch0_harq->mimo_mode == TM7))
{
/*
dlsch_siso(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp,
pdsch_vars[eNB_id_i]->rxdataF_comp,
symbol,
nb_rb);
*/
}
else if(dlsch0_harq->mimo_mode == ALAMOUTI)
{
dlsch_alamouti(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
symbol,
nb_rb);
}
// printf("LLR");
if((dlsch0_harq->mimo_mode == LARGE_CDD) ||
((dlsch0_harq->mimo_mode >= DUALSTREAM_UNIFORM_PRECODING1) &&
(dlsch0_harq->mimo_mode <= DUALSTREAM_PUSCH_PRECODING)))
{
rxdataF_comp_ptr = pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round];
dl_ch_mag_ptr = pdsch_vars[eNB_id]->dl_ch_mag1[harq_pid][round];
}
else
{
rxdataF_comp_ptr = pdsch_vars[eNB_id_i]->rxdataF_comp0;
dl_ch_mag_ptr = pdsch_vars[eNB_id_i]->dl_ch_mag0;
//i_mod should have been passed as a parameter
}
#if UE_TIMING_TRACE
stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n", frame, subframe, slot, symbol, ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time / (cpuf * 1000.0));
start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
#endif
//printf("LLR dlsch0_harq->Qm %d rx_type %d cw0 %d cw1 %d symbol %d \n",dlsch0_harq->Qm,rx_type,codeword_TB0,codeword_TB1,symbol);
// compute LLRs
// -> // compute @pointer where llrs should filled for this ofdm-symbol
int8_t *pllr_symbol_cw0;
int8_t *pllr_symbol_cw1;
uint32_t llr_offset_symbol;
llr_offset_symbol = pdsch_vars[eNB_id]->llr_offset[symbol];
pllr_symbol_cw0 = (int8_t *)pdsch_vars[eNB_id]->llr[0];
pllr_symbol_cw1 = (int8_t *)pdsch_vars[eNB_id]->llr[1];
pllr_symbol_cw0 += llr_offset_symbol;
pllr_symbol_cw1 += llr_offset_symbol;
/*
LOG_I(PHY,"compute LLRs [AbsSubframe %d.%d-%d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %p @LLR Buff(symb) %p\n",
frame, subframe,symbol,
nb_rb,dlsch0_harq->Qm,
pdsch_vars[eNB_id]->llr_length[symbol],
pdsch_vars[eNB_id]->llr_offset[symbol],
(int16_t*)pdsch_vars[eNB_id]->llr[0],
pllr_symbol_cw0);
*/
switch(dlsch0_harq->Qm)
{
case 2 :
if((rx_type == rx_standard) || (codeword_TB1 == -1))
{
dlsch_qpsk_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
(int16_t *)pllr_symbol_cw0,
symbol,
first_symbol_flag,
nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 2, subframe, symbol),
beamforming_mode);
}
else if(codeword_TB0 == -1)
{
dlsch_qpsk_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
(int16_t *)pllr_symbol_cw1,
symbol,
first_symbol_flag,
nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 2, subframe, symbol),
beamforming_mode);
}
else if(rx_type >= rx_IC_single_stream)
{
if(dlsch1_harq->Qm == 2)
{
dlsch_qpsk_qpsk_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 2, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_qpsk_qpsk_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 2, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
else if(dlsch1_harq->Qm == 4)
{
dlsch_qpsk_16qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
dl_ch_mag_ptr,//i
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 2, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_16qam_qpsk_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,//i
dl_ch_mag_ptr,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
else
{
dlsch_qpsk_64qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
dl_ch_mag_ptr,//i
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 2, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_64qam_qpsk_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,//i
dl_ch_mag_ptr,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
}
break;
case 4 :
if((rx_type == rx_standard) || (codeword_TB1 == -1))
{
dlsch_16qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id]->llr[0],
pdsch_vars[eNB_id]->dl_ch_mag0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128,
beamforming_mode);
}
else if(codeword_TB0 == -1)
{
dlsch_16qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id]->llr[1],
pdsch_vars[eNB_id]->dl_ch_mag0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream,
beamforming_mode);
}
else if(rx_type >= rx_IC_single_stream)
{
if(dlsch1_harq->Qm == 2)
{
dlsch_16qam_qpsk_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_qpsk_16qam_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,//i
pdsch_vars[eNB_id]->dl_ch_mag0,//i
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 2, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
else if(dlsch1_harq->Qm == 4)
{
dlsch_16qam_16qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
pdsch_vars[eNB_id]->dl_ch_mag0,
dl_ch_mag_ptr,//i
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_16qam_16qam_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,//i
dl_ch_mag_ptr,
pdsch_vars[eNB_id]->dl_ch_mag0,//i
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
else
{
dlsch_16qam_64qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
pdsch_vars[eNB_id]->dl_ch_mag0,
dl_ch_mag_ptr,//i
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_64qam_16qam_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,
dl_ch_mag_ptr,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
}
break;
case 6 :
if((rx_type == rx_standard) || (codeword_TB1 == -1))
{
dlsch_64qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
(int16_t *)pllr_symbol_cw0,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr_offset[symbol],
beamforming_mode);
}
else if(codeword_TB0 == -1)
{
dlsch_64qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
(int16_t *)pllr_symbol_cw1,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr_offset[symbol],
beamforming_mode);
}
else if(rx_type >= rx_IC_single_stream)
{
if(dlsch1_harq->Qm == 2)
{
dlsch_64qam_qpsk_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_qpsk_64qam_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,//i
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 2, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
else if(dlsch1_harq->Qm == 4)
{
dlsch_64qam_16qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
pdsch_vars[eNB_id]->dl_ch_mag0,
dl_ch_mag_ptr,//i
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
pdsch_vars[eNB_id]->llr[0],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr128);
if(rx_type == rx_IC_dual_stream)
{
dlsch_16qam_64qam_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,//i
dl_ch_mag_ptr,
pdsch_vars[eNB_id]->dl_ch_mag0,//i
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
pdsch_vars[eNB_id]->llr[1],
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128_2ndstream);
}
}
else
{
dlsch_64qam_64qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
rxdataF_comp_ptr,//i
pdsch_vars[eNB_id]->dl_ch_mag0,
dl_ch_mag_ptr,//i
pdsch_vars[eNB_id]->dl_ch_rho2_ext,
(int16_t *)pllr_symbol_cw0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr_offset[symbol]);
if(rx_type == rx_IC_dual_stream)
{
dlsch_64qam_64qam_llr(frame_parms,
rxdataF_comp_ptr,
pdsch_vars[eNB_id]->rxdataF_comp0,//i
dl_ch_mag_ptr,
pdsch_vars[eNB_id]->dl_ch_mag0,//i
pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round],
(int16_t *)pllr_symbol_cw1,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch1_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr_offset[symbol]);
}
}
}
break;
default:
LOG_W(PHY, "rx_dlsch.c : Unknown mod_order!!!!\n");
return(-1);
break;
}
if(dlsch1_harq)
{
switch(get_Qm(dlsch1_harq->mcs))
{
case 2 :
if(rx_type == rx_standard)
{
dlsch_qpsk_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
(int16_t *)pllr_symbol_cw0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 2, subframe, symbol),
beamforming_mode);
}
break;
case 4:
if(rx_type == rx_standard)
{
dlsch_16qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
pdsch_vars[eNB_id]->llr[0],
pdsch_vars[eNB_id]->dl_ch_mag0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 4, subframe, symbol),
pdsch_vars[eNB_id]->llr128,
beamforming_mode);
}
break;
case 6 :
if(rx_type == rx_standard)
{
dlsch_64qam_llr(frame_parms,
pdsch_vars[eNB_id]->rxdataF_comp0,
(int16_t *)pllr_symbol_cw0,
pdsch_vars[eNB_id]->dl_ch_mag0,
pdsch_vars[eNB_id]->dl_ch_magb0,
symbol, first_symbol_flag, nb_rb,
adjust_G2(frame_parms, dlsch0_harq->rb_alloc_even, 6, subframe, symbol),
pdsch_vars[eNB_id]->llr_offset[symbol],
beamforming_mode);
}
break;
default:
LOG_W(PHY, "rx_dlsch.c : Unknown mod_order!!!!\n");
return(-1);
break;
}
}
#if UE_TIMING_TRACE
stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]);
LOG_D(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation %5.2f \n", frame, subframe, slot, symbol, ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time / (cpuf * 1000.0));
#endif
// Please keep it: useful for debugging
T(T_UE_PHY_PDSCH_IQ, T_INT(eNB_id), T_INT(frame % 1024),
T_INT(subframe), T_INT(nb_rb),
T_INT(frame_parms->N_RB_UL), T_INT(frame_parms->symbols_per_tti),
T_BUFFER(&pdsch_vars[eNB_id]->rxdataF_comp0[eNB_id][0],
2 * /* ulsch[UE_id]->harq_processes[harq_pid]->nb_rb */ frame_parms->N_RB_UL * 12 * frame_parms->symbols_per_tti * 2));
return 0;
}
//==============================================================================================
// Pre-processing for LLR computation
//==============================================================================================
void dlsch_channel_compensation(int **rxdataF_ext,
int **dl_ch_estimates_ext,
int **dl_ch_mag,
int **dl_ch_magb,
int **rxdataF_comp,
int **rho,
LTE_DL_FRAME_PARMS *frame_parms,
unsigned char symbol,
uint8_t first_symbol_flag,
unsigned char mod_order,
unsigned short nb_rb,
unsigned char output_shift,
PHY_MEASUREMENTS *measurements)
{
#if defined(__i386) || defined(__x86_64)
unsigned short rb;
unsigned char aatx, aarx, symbol_mod, pilots = 0;
__m128i *dl_ch128, *dl_ch128_2, *dl_ch_mag128, *dl_ch_mag128b, *rxdataF128, *rxdataF_comp128, *rho128;
__m128i mmtmpD0, mmtmpD1, mmtmpD2, mmtmpD3, QAM_amp128;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
if(frame_parms->nb_antenna_ports_eNB == 1) // 10 out of 12 so don't reduce size
{
nb_rb = 1 + (5 * nb_rb / 6);
}
else
{
pilots = 1;
}
}
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
{
__m128i QAM_amp128b = _mm_setzero_si128();
if(mod_order == 4)
{
QAM_amp128 = _mm_set1_epi16(QAM16_n1); // 2/sqrt(10)
}
else if(mod_order == 6)
{
QAM_amp128 = _mm_set1_epi16(QAM64_n1); //
QAM_amp128b = _mm_set1_epi16(QAM64_n2);
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
/* TODO: hack to be removed. There is crash for 1 antenna case, so
for 1 antenna case, I put back the value 2 as it was before
Elena's commit.
*/
int x = frame_parms->nb_antennas_rx > 1 ? frame_parms->nb_antennas_rx : 2;
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx * x + aarx][symbol * frame_parms->N_RB_DL * 12];
//print_shorts("dl_ch128[0]=",&dl_ch128[0]);*/
dl_ch_mag128 = (__m128i *)&dl_ch_mag[aatx * x + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128b = (__m128i *)&dl_ch_magb[aatx * x + aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF128 = (__m128i *)&rxdataF_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128 = (__m128i *)&rxdataF_comp[aatx * x + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
if(mod_order > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = _mm_madd_epi16(dl_ch128[0], dl_ch128[0]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_madd_epi16(dl_ch128[1], dl_ch128[1]);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD0 = _mm_packs_epi32(mmtmpD0, mmtmpD1);
// store channel magnitude here in a new field of dlsch
dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag128b[0] = dl_ch_mag128[0];
dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0], QAM_amp128);
dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0], 1);
//print_ints("Re(ch):",(int16_t*)&mmtmpD0);
//print_shorts("QAM_amp:",(int16_t*)&QAM_amp128);
//print_shorts("mag:",(int16_t*)&dl_ch_mag128[0]);
dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag128b[1] = dl_ch_mag128[1];
dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1], QAM_amp128);
dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1], 1);
if(pilots == 0)
{
mmtmpD0 = _mm_madd_epi16(dl_ch128[2], dl_ch128[2]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_packs_epi32(mmtmpD0, mmtmpD0);
dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1, mmtmpD1);
dl_ch_mag128b[2] = dl_ch_mag128[2];
dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2], QAM_amp128);
dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2], 1);
}
dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0], QAM_amp128b);
dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0], 1);
dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1], QAM_amp128b);
dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1], 1);
if(pilots == 0)
{
dl_ch_mag128b[2] = _mm_mulhi_epi16(dl_ch_mag128b[2], QAM_amp128b);
dl_ch_mag128b[2] = _mm_slli_epi16(dl_ch_mag128b[2], 1);
}
}
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[0], rxdataF128[0]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
// print_ints("im",&mmtmpD1);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[0]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
rxdataF_comp128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128);
// print_shorts("ch:",dl_ch128);
// print_shorts("pack:",rxdataF_comp128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[1], rxdataF128[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+1);
// print_shorts("ch:",dl_ch128+1);
// print_shorts("pack:",rxdataF_comp128+1);
if(pilots == 0)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[2], rxdataF128[2]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[2]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+2);
// print_shorts("ch:",dl_ch128+2);
// print_shorts("pack:",rxdataF_comp128+2);
dl_ch128 += 3;
dl_ch_mag128 += 3;
dl_ch_mag128b += 3;
rxdataF128 += 3;
rxdataF_comp128 += 3;
}
else // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less
{
dl_ch128 += 2;
dl_ch_mag128 += 2;
dl_ch_mag128b += 2;
rxdataF128 += 2;
rxdataF_comp128 += 2;
}
}
}
}
if(rho)
{
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
rho128 = (__m128i *)&rho[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch128_2 = (__m128i *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[0], dl_ch128_2[0]);
// print_ints("re",&mmtmpD0);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
// print_ints("im",&mmtmpD1);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128_2[0]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
rho128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
//print_shorts("rx:",dl_ch128_2);
//print_shorts("ch:",dl_ch128);
//print_shorts("pack:",rho128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[1], dl_ch128_2[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128_2[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rho128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
//print_shorts("rx:",dl_ch128_2+1);
//print_shorts("ch:",dl_ch128+1);
//print_shorts("pack:",rho128+1);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[2], dl_ch128_2[2]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128_2[2]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rho128[2] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
//print_shorts("rx:",dl_ch128_2+2);
//print_shorts("ch:",dl_ch128+2);
//print_shorts("pack:",rho128+2);
dl_ch128 += 3;
dl_ch128_2 += 3;
rho128 += 3;
}
if(first_symbol_flag == 1)
{
measurements->rx_correlation[0][aarx] = signal_energy(&rho[aarx][symbol * frame_parms->N_RB_DL * 12], rb * 12);
}
}
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
unsigned short rb;
unsigned char aatx, aarx, symbol_mod, pilots = 0;
int16x4_t *dl_ch128, *dl_ch128_2, *rxdataF128;
int32x4_t mmtmpD0, mmtmpD1, mmtmpD0b, mmtmpD1b;
int16x8_t *dl_ch_mag128, *dl_ch_mag128b, mmtmpD2, mmtmpD3, mmtmpD4;
int16x8_t QAM_amp128, QAM_amp128b;
int16x4x2_t *rxdataF_comp128, *rho128;
int16_t conj[4]__attribute__((aligned(16))) = {1, -1, 1, -1};
int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift);
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
if(frame_parms->nb_antenna_ports_eNB == 1) // 10 out of 12 so don't reduce size
{
nb_rb = 1 + (5 * nb_rb / 6);
}
else
{
pilots = 1;
}
}
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
{
if(mod_order == 4)
{
QAM_amp128 = vmovq_n_s16(QAM16_n1); // 2/sqrt(10)
QAM_amp128b = vmovq_n_s16(0);
}
else if(mod_order == 6)
{
QAM_amp128 = vmovq_n_s16(QAM64_n1); //
QAM_amp128b = vmovq_n_s16(QAM64_n2);
}
// printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol);
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch128 = (int16x4_t *)&dl_ch_estimates_ext[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128 = (int16x8_t *)&dl_ch_mag[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128b = (int16x8_t *)&dl_ch_magb[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF128 = (int16x4_t *)&rxdataF_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128 = (int16x4x2_t *)&rxdataF_comp[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
if(mod_order > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128[0]);
// mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3];
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
// mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits
mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128[1]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
// mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits
mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128[2]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128[3]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
if(pilots == 0)
{
mmtmpD0 = vmull_s16(dl_ch128[4], dl_ch128[4]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch128[5], dl_ch128[5]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
}
dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2, QAM_amp128b);
dl_ch_mag128b[1] = vqdmulhq_s16(mmtmpD3, QAM_amp128b);
dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2, QAM_amp128);
dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3, QAM_amp128);
if(pilots == 0)
{
dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4, QAM_amp128b);
dl_ch_mag128[2] = vqdmulhq_s16(mmtmpD4, QAM_amp128);
}
}
mmtmpD0 = vmull_s16(dl_ch128[0], rxdataF128[0]);
//mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])]
mmtmpD1 = vmull_s16(dl_ch128[1], rxdataF128[1]);
//mmtmpD1 = [Re(ch[2])Re(rx[2]) Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3]) Im(ch[3])Im(ch[3])]
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
//mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])]
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0], *(int16x4_t *)conj)), rxdataF128[0]);
//mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1], *(int16x4_t *)conj)), rxdataF128[1]);
//mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
//mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp128[0] = vzip_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
mmtmpD0 = vmull_s16(dl_ch128[2], rxdataF128[2]);
mmtmpD1 = vmull_s16(dl_ch128[3], rxdataF128[3]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2], *(int16x4_t *)conj)), rxdataF128[2]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3], *(int16x4_t *)conj)), rxdataF128[3]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp128[1] = vzip_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
if(pilots == 0)
{
mmtmpD0 = vmull_s16(dl_ch128[4], rxdataF128[4]);
mmtmpD1 = vmull_s16(dl_ch128[5], rxdataF128[5]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4], *(int16x4_t *)conj)), rxdataF128[4]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5], *(int16x4_t *)conj)), rxdataF128[5]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp128[2] = vzip_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
dl_ch128 += 6;
dl_ch_mag128 += 3;
dl_ch_mag128b += 3;
rxdataF128 += 6;
rxdataF_comp128 += 3;
}
else // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less
{
dl_ch128 += 4;
dl_ch_mag128 += 2;
dl_ch_mag128b += 2;
rxdataF128 += 4;
rxdataF_comp128 += 2;
}
}
}
}
if(rho)
{
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
rho128 = (int16x4x2_t *)&rho[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch128 = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch128_2 = (int16x4_t *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]);
mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0], *(int16x4_t *)conj)), dl_ch128_2[0]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1], *(int16x4_t *)conj)), dl_ch128_2[1]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rho128[0] = vzip_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128_2[2]);
mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128_2[3]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2], *(int16x4_t *)conj)), dl_ch128_2[2]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3], *(int16x4_t *)conj)), dl_ch128_2[3]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rho128[1] = vzip_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]);
mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4], *(int16x4_t *)conj)), dl_ch128_2[4]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5], *(int16x4_t *)conj)), dl_ch128_2[5]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rho128[2] = vzip_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
dl_ch128 += 6;
dl_ch128_2 += 6;
rho128 += 3;
}
if(first_symbol_flag == 1)
{
measurements->rx_correlation[0][aarx] = signal_energy(&rho[aarx][symbol * frame_parms->N_RB_DL * 12], rb * 12);
}
}
}
#endif
}
void dlsch_channel_compensation_core(int **rxdataF_ext,
int **dl_ch_estimates_ext,
int **dl_ch_mag,
int **dl_ch_magb,
int **rxdataF_comp,
int **rho,
unsigned char n_tx,
unsigned char n_rx,
unsigned char mod_order,
unsigned char output_shift,
int length,
int start_point)
{
unsigned short ii;
int length_mod8 = 0;
int length2;
__m128i *dl_ch128, *dl_ch_mag128, *dl_ch_mag128b, *dl_ch128_2, *rxdataF128, *rxdataF_comp128, *rho128;
__m128i mmtmpD0, mmtmpD1, mmtmpD2, mmtmpD3, QAM_amp128;
int aatx = 0, aarx = 0;
for(aatx = 0; aatx < n_tx; aatx++)
{
__m128i QAM_amp128b;
if(mod_order == 4)
{
QAM_amp128 = _mm_set1_epi16(QAM16_n1); // 2/sqrt(10)
QAM_amp128b = _mm_setzero_si128();
}
else if(mod_order == 6)
{
QAM_amp128 = _mm_set1_epi16(QAM64_n1); //
QAM_amp128b = _mm_set1_epi16(QAM64_n2);
}
for(aarx = 0; aarx < n_rx; aarx++)
{
/* TODO: hack to be removed. There is crash for 1 antenna case, so
for 1 antenna case, I put back the value 2 as it was before
Elena's commit.
*/
int x = n_rx > 1 ? n_rx : 2;
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx * x + aarx][start_point];
dl_ch_mag128 = (__m128i *)&dl_ch_mag[aatx * x + aarx][start_point];
dl_ch_mag128b = (__m128i *)&dl_ch_magb[aatx * x + aarx][start_point];
rxdataF128 = (__m128i *)&rxdataF_ext[aarx][start_point];
rxdataF_comp128 = (__m128i *)&rxdataF_comp[aatx * x + aarx][start_point];
length_mod8 = length & 7;
if(length_mod8 == 0)
{
length2 = length >> 3;
for(ii = 0; ii < length2; ++ii)
{
if(mod_order > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = _mm_madd_epi16(dl_ch128[0], dl_ch128[0]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_madd_epi16(dl_ch128[1], dl_ch128[1]);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD0 = _mm_packs_epi32(mmtmpD0, mmtmpD1);
// store channel magnitude here in a new field of dlsch
dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag128b[0] = dl_ch_mag128[0];
dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0], QAM_amp128);
dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0], 1);
//print_ints("Re(ch):",(int16_t*)&mmtmpD0);
//print_shorts("QAM_amp:",(int16_t*)&QAM_amp128);
//print_shorts("mag:",(int16_t*)&dl_ch_mag128[0]);
dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag128b[1] = dl_ch_mag128[1];
dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1], QAM_amp128);
dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1], 1);
dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0], QAM_amp128b);
dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0], 1);
dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1], QAM_amp128b);
dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1], 1);
}
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[0], rxdataF128[0]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
// print_ints("im",&mmtmpD1);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[0]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
rxdataF_comp128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128);
// print_shorts("ch:",dl_ch128);
// print_shorts("pack:",rxdataF_comp128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[1], rxdataF128[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+1);
// print_shorts("ch:",dl_ch128+1);
//print_shorts("pack:",rxdataF_comp128+1);
dl_ch128 += 2;
dl_ch_mag128 += 2;
dl_ch_mag128b += 2;
rxdataF128 += 2;
rxdataF_comp128 += 2;
}
}
else
{
printf("Channel Compensation: Received number of subcarriers is not multiple of 8, \n"
"need to adapt the code!\n");
}
}
}
/*This part of code makes sense only for processing in 2x2 blocks*/
if(rho)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
rho128 = (__m128i *)&rho[aarx][start_point];
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][start_point];
dl_ch128_2 = (__m128i *)&dl_ch_estimates_ext[2 + aarx][start_point];
if(length_mod8 == 0)
{
length2 = length >> 3;
for(ii = 0; ii < length2; ++ii)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[0], dl_ch128_2[0]);
// print_ints("re",&mmtmpD0);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
// print_ints("im",&mmtmpD1);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128_2[0]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
rho128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
//print_shorts("rx:",dl_ch128_2);
//print_shorts("ch:",dl_ch128);
//print_shorts("pack:",rho128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[1], dl_ch128_2[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128_2[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rho128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
dl_ch128 += 2;
dl_ch128_2 += 2;
rho128 += 2;
}
}
else
{
printf("Channel Compensation: Received number of subcarriers is not multiple of 8, \n"
"need to adapt the code!\n");
}
}
}
_mm_empty();
_m_empty();
}
#if defined(__x86_64__) || defined(__i386__)
void prec2A_TM56_128(unsigned char pmi, __m128i *ch0, __m128i *ch1)
{
__m128i amp;
amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
switch(pmi)
{
case 0 : // +1 +1
// print_shorts("phase 0 :ch0",ch0);
// print_shorts("phase 0 :ch1",ch1);
ch0[0] = _mm_adds_epi16(ch0[0], ch1[0]);
break;
case 1 : // +1 -1
// print_shorts("phase 1 :ch0",ch0);
// print_shorts("phase 1 :ch1",ch1);
ch0[0] = _mm_subs_epi16(ch0[0], ch1[0]);
// print_shorts("phase 1 :ch0-ch1",ch0);
break;
case 2 : // +1 +j
ch1[0] = _mm_sign_epi16(ch1[0], *(__m128i *)&conjugate[0]);
ch1[0] = _mm_shufflelo_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch1[0] = _mm_shufflehi_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch0[0] = _mm_subs_epi16(ch0[0], ch1[0]);
break; // +1 -j
case 3 :
ch1[0] = _mm_sign_epi16(ch1[0], *(__m128i *)&conjugate[0]);
ch1[0] = _mm_shufflelo_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch1[0] = _mm_shufflehi_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch0[0] = _mm_adds_epi16(ch0[0], ch1[0]);
break;
}
ch0[0] = _mm_mulhi_epi16(ch0[0], amp);
ch0[0] = _mm_slli_epi16(ch0[0], 1);
_mm_empty();
_m_empty();
}
#elif defined(__arm__)
void prec2A_TM56_128(unsigned char pmi, __m128i *ch0, __m128i *ch1)
{
// sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b,
//so removed it
//__m128i amp;
//amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
switch(pmi)
{
case 0 : // +1 +1
// print_shorts("phase 0 :ch0",ch0);
// print_shorts("phase 0 :ch1",ch1);
ch0[0] = _mm_adds_epi16(ch0[0], ch1[0]);
break;
case 1 : // +1 -1
// print_shorts("phase 1 :ch0",ch0);
// print_shorts("phase 1 :ch1",ch1);
ch0[0] = _mm_subs_epi16(ch0[0], ch1[0]);
// print_shorts("phase 1 :ch0-ch1",ch0);
break;
case 2 : // +1 +j
ch1[0] = _mm_sign_epi16(ch1[0], *(__m128i *)&conjugate[0]);
ch1[0] = _mm_shufflelo_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch1[0] = _mm_shufflehi_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch0[0] = _mm_subs_epi16(ch0[0], ch1[0]);
break; // +1 -j
case 3 :
ch1[0] = _mm_sign_epi16(ch1[0], *(__m128i *)&conjugate[0]);
ch1[0] = _mm_shufflelo_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch1[0] = _mm_shufflehi_epi16(ch1[0], _MM_SHUFFLE(2, 3, 0, 1));
ch0[0] = _mm_adds_epi16(ch0[0], ch1[0]);
break;
}
//ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
//ch0[0] = _mm_slli_epi16(ch0[0],1);
_mm_empty();
_m_empty();
}
#endif
// precoding is stream 0 .5(1,1) .5(1,-1) .5(1,1) .5(1,-1)
// stream 1 .5(1,-1) .5(1,1) .5(1,-1) .5(1,1)
// store "precoded" channel for stream 0 in ch0, stream 1 in ch1
short TM3_prec[8]__attribute__((aligned(16))) = {1, 1, -1, -1, 1, 1, -1, -1} ;
void prec2A_TM3_128(__m128i *ch0, __m128i *ch1)
{
__m128i amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
__m128i tmp0, tmp1;
//_mm_mulhi_epi16
// print_shorts("prec2A_TM3 ch0 (before):",ch0);
// print_shorts("prec2A_TM3 ch1 (before):",ch1);
tmp0 = ch0[0];
tmp1 = _mm_sign_epi16(ch1[0], ((__m128i *)&TM3_prec)[0]);
// print_shorts("prec2A_TM3 ch1*s (mid):",(__m128i*)TM3_prec);
ch0[0] = _mm_adds_epi16(ch0[0], tmp1);
ch1[0] = _mm_subs_epi16(tmp0, tmp1);
ch0[0] = _mm_mulhi_epi16(ch0[0], amp);
ch0[0] = _mm_slli_epi16(ch0[0], 1);
ch1[0] = _mm_mulhi_epi16(ch1[0], amp);
ch1[0] = _mm_slli_epi16(ch1[0], 1);
// print_shorts("prec2A_TM3 ch0 (mid):",&tmp0);
// print_shorts("prec2A_TM3 ch1 (mid):",ch1);
//ch0[0] = _mm_mulhi_epi16(ch0[0],amp);
//ch0[0] = _mm_slli_epi16(ch0[0],1);
//ch1[0] = _mm_mulhi_epi16(ch1[0],amp);
//ch1[0] = _mm_slli_epi16(ch1[0],1);
//ch0[0] = _mm_srai_epi16(ch0[0],1);
//ch1[0] = _mm_srai_epi16(ch1[0],1);
// print_shorts("prec2A_TM3 ch0 (after):",ch0);
// print_shorts("prec2A_TM3 ch1 (after):",ch1);
_mm_empty();
_m_empty();
}
// pmi = 0 => stream 0 (1,1), stream 1 (1,-1)
// pmi = 1 => stream 0 (1,j), stream 2 (1,-j)
void prec2A_TM4_128(int pmi, __m128i *ch0, __m128i *ch1)
{
// sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b,
//so divide by 2 is replaced by divide by sqrt(2).
// printf ("demod pmi=%d\n", pmi);
__m128i amp;
amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15);
__m128i tmp0, tmp1;
// print_shorts("prec2A_TM4 ch0 (before):",ch0);
// print_shorts("prec2A_TM4 ch1 (before):",ch1);
if(pmi == 0) //[1 1;1 -1]
{
tmp0 = ch0[0];
tmp1 = ch1[0];
ch0[0] = _mm_adds_epi16(tmp0, tmp1);
ch1[0] = _mm_subs_epi16(tmp0, tmp1);
}
else //ch0+j*ch1 ch0-j*ch1
{
tmp0 = ch0[0];
tmp1 = _mm_sign_epi16(ch1[0], *(__m128i *)&conjugate[0]);
tmp1 = _mm_shufflelo_epi16(tmp1, _MM_SHUFFLE(2, 3, 0, 1));
tmp1 = _mm_shufflehi_epi16(tmp1, _MM_SHUFFLE(2, 3, 0, 1));
ch0[0] = _mm_subs_epi16(tmp0, tmp1);
ch1[0] = _mm_add_epi16(tmp0, tmp1);
}
//print_shorts("prec2A_TM4 ch0 (middle):",ch0);
//print_shorts("prec2A_TM4 ch1 (middle):",ch1);
ch0[0] = _mm_mulhi_epi16(ch0[0], amp);
ch0[0] = _mm_slli_epi16(ch0[0], 1);
ch1[0] = _mm_mulhi_epi16(ch1[0], amp);
ch1[0] = _mm_slli_epi16(ch1[0], 1);
// ch0[0] = _mm_srai_epi16(ch0[0],1); //divide by 2
// ch1[0] = _mm_srai_epi16(ch1[0],1); //divide by 2
//print_shorts("prec2A_TM4 ch0 (end):",ch0);
//print_shorts("prec2A_TM4 ch1 (end):",ch1);
_mm_empty();
_m_empty();
// print_shorts("prec2A_TM4 ch0 (end):",ch0);
//print_shorts("prec2A_TM4 ch1 (end):",ch1);
}
void dlsch_channel_compensation_TM56(int **rxdataF_ext,
int **dl_ch_estimates_ext,
int **dl_ch_mag,
int **dl_ch_magb,
int **rxdataF_comp,
unsigned char *pmi_ext,
LTE_DL_FRAME_PARMS *frame_parms,
PHY_MEASUREMENTS *measurements,
int eNB_id,
unsigned char symbol,
unsigned char mod_order,
unsigned short nb_rb,
unsigned char output_shift,
unsigned char dl_power_off)
{
#if defined(__x86_64__) || defined(__i386__)
unsigned short rb, Nre;
__m128i *dl_ch0_128, *dl_ch1_128, *dl_ch_mag128, *dl_ch_mag128b, *rxdataF128, *rxdataF_comp128;
unsigned char aarx = 0, symbol_mod, pilots = 0;
int precoded_signal_strength = 0;
__m128i mmtmpD0, mmtmpD1, mmtmpD2, mmtmpD3, QAM_amp128;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
pilots = 1;
}
//printf("comp prec: symbol %d, pilots %d\n",symbol, pilots);
__m128i QAM_amp128b = _mm_setzero_si128();
if(mod_order == 4)
{
QAM_amp128 = _mm_set1_epi16(QAM16_n1);
}
else if(mod_order == 6)
{
QAM_amp128 = _mm_set1_epi16(QAM64_n1);
QAM_amp128b = _mm_set1_epi16(QAM64_n2);
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128 = (__m128i *)&dl_ch_mag[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128b = (__m128i *)&dl_ch_magb[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF128 = (__m128i *)&rxdataF_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128 = (__m128i *)&rxdataF_comp[aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
// combine TX channels using precoder from pmi
#ifdef DEBUG_DLSCH_DEMOD
printf("mode 6 prec: rb %d, pmi->%d\n", rb, pmi_ext[rb]);
#endif
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128[2], &dl_ch1_128[2]);
}
if(mod_order > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0], dl_ch0_128[0]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1], dl_ch0_128[1]);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD0 = _mm_packs_epi32(mmtmpD0, mmtmpD1);
dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag128b[0] = dl_ch_mag128[0];
dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0], QAM_amp128);
dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0], 1);
//print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]);
//print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]);
dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag128b[1] = dl_ch_mag128[1];
dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1], QAM_amp128);
dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1], 1);
if(pilots == 0)
{
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2], dl_ch0_128[2]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_packs_epi32(mmtmpD0, mmtmpD0);
dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1, mmtmpD1);
dl_ch_mag128b[2] = dl_ch_mag128[2];
dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2], QAM_amp128);
dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2], 1);
}
dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0], QAM_amp128b);
dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0], 1);
//print_shorts("dl_ch_mag128b[0]=",&dl_ch_mag128b[0]);
dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1], QAM_amp128b);
dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1], 1);
if(pilots == 0)
{
dl_ch_mag128b[2] = _mm_mulhi_epi16(dl_ch_mag128b[2], QAM_amp128b);
dl_ch_mag128b[2] = _mm_slli_epi16(dl_ch_mag128b[2], 1);
}
}
// MF multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0], rxdataF128[0]);
// print_ints("re",&mmtmpD0);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
// print_ints("im",&mmtmpD1);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[0]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
rxdataF_comp128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128);
// print_shorts("ch:",dl_ch128);
// print_shorts("pack:",rxdataF_comp128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1], rxdataF128[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+1);
// print_shorts("ch:",dl_ch128+1);
// print_shorts("pack:",rxdataF_comp128+1);
if(pilots == 0)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2], rxdataF128[2]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[2]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+2);
// print_shorts("ch:",dl_ch128+2);
// print_shorts("pack:",rxdataF_comp128+2);
dl_ch0_128 += 3;
dl_ch1_128 += 3;
dl_ch_mag128 += 3;
dl_ch_mag128b += 3;
rxdataF128 += 3;
rxdataF_comp128 += 3;
}
else
{
dl_ch0_128 += 2;
dl_ch1_128 += 2;
dl_ch_mag128 += 2;
dl_ch_mag128b += 2;
rxdataF128 += 2;
rxdataF_comp128 += 2;
}
}
Nre = (pilots == 0) ? 12 : 8;
precoded_signal_strength += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * Nre],
(nb_rb * Nre))) - (measurements->n0_power[aarx]));
} // rx_antennas
measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength, measurements->n0_power_tot);
//printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
// measurements->precoded_cqi_dB[eNB_id][0]);
#elif defined(__arm__)
uint32_t rb, Nre;
uint32_t aarx, symbol_mod, pilots = 0;
int16x4_t *dl_ch0_128, *dl_ch1_128, *rxdataF128;
int16x8_t *dl_ch0_128b, *dl_ch1_128b;
int32x4_t mmtmpD0, mmtmpD1, mmtmpD0b, mmtmpD1b;
int16x8_t *dl_ch_mag128, *dl_ch_mag128b, mmtmpD2, mmtmpD3, mmtmpD4, *rxdataF_comp128;
int16x8_t QAM_amp128, QAM_amp128b;
int16_t conj[4]__attribute__((aligned(16))) = {1, -1, 1, -1};
int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift);
int32_t precoded_signal_strength = 0;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
if(frame_parms->nb_antenna_ports_eNB == 1) // 10 out of 12 so don't reduce size
{
nb_rb = 1 + (5 * nb_rb / 6);
}
else
{
pilots = 1;
}
}
if(mod_order == 4)
{
QAM_amp128 = vmovq_n_s16(QAM16_n1); // 2/sqrt(10)
QAM_amp128b = vmovq_n_s16(0);
}
else if(mod_order == 6)
{
QAM_amp128 = vmovq_n_s16(QAM64_n1); //
QAM_amp128b = vmovq_n_s16(QAM64_n2);
}
// printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol);
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch0_128 = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch1_128 = (int16x4_t *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch0_128b = (int16x8_t *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch1_128b = (int16x8_t *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128 = (int16x8_t *)&dl_ch_mag[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128b = (int16x8_t *)&dl_ch_magb[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF128 = (int16x4_t *)&rxdataF_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128 = (int16x8_t *)&rxdataF_comp[aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
#ifdef DEBUG_DLSCH_DEMOD
printf("mode 6 prec: rb %d, pmi->%u\n", rb, pmi_ext[rb]);
#endif
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128b[0], &dl_ch1_128b[0]);
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128b[1], &dl_ch1_128b[1]);
if(pilots == 0)
{
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128b[2], &dl_ch1_128b[2]);
}
if(mod_order > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = vmull_s16(dl_ch0_128[0], dl_ch0_128[0]);
// mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3];
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
// mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits
mmtmpD1 = vmull_s16(dl_ch0_128[1], dl_ch0_128[1]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
// mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits
mmtmpD0 = vmull_s16(dl_ch0_128[2], dl_ch0_128[2]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch0_128[3], dl_ch0_128[3]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
if(pilots == 0)
{
mmtmpD0 = vmull_s16(dl_ch0_128[4], dl_ch0_128[4]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch0_128[5], dl_ch0_128[5]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
}
dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2, QAM_amp128b);
dl_ch_mag128b[1] = vqdmulhq_s16(mmtmpD3, QAM_amp128b);
dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2, QAM_amp128);
dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3, QAM_amp128);
if(pilots == 0)
{
dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4, QAM_amp128b);
dl_ch_mag128[2] = vqdmulhq_s16(mmtmpD4, QAM_amp128);
}
}
mmtmpD0 = vmull_s16(dl_ch0_128[0], rxdataF128[0]);
//mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])]
mmtmpD1 = vmull_s16(dl_ch0_128[1], rxdataF128[1]);
//mmtmpD1 = [Re(ch[2])Re(rx[2]) Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3]) Im(ch[3])Im(ch[3])]
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
//mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])]
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0], *(int16x4_t *)conj)), rxdataF128[0]);
//mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1], *(int16x4_t *)conj)), rxdataF128[1]);
//mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
//mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp128[0] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
mmtmpD0 = vmull_s16(dl_ch0_128[2], rxdataF128[2]);
mmtmpD1 = vmull_s16(dl_ch0_128[3], rxdataF128[3]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2], *(int16x4_t *)conj)), rxdataF128[2]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3], *(int16x4_t *)conj)), rxdataF128[3]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp128[1] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
if(pilots == 0)
{
mmtmpD0 = vmull_s16(dl_ch0_128[4], rxdataF128[4]);
mmtmpD1 = vmull_s16(dl_ch0_128[5], rxdataF128[5]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4], *(int16x4_t *)conj)), rxdataF128[4]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5], *(int16x4_t *)conj)), rxdataF128[5]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp128[2] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
dl_ch0_128 += 6;
dl_ch1_128 += 6;
dl_ch_mag128 += 3;
dl_ch_mag128b += 3;
rxdataF128 += 6;
rxdataF_comp128 += 3;
}
else // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less
{
dl_ch0_128 += 4;
dl_ch1_128 += 4;
dl_ch_mag128 += 2;
dl_ch_mag128b += 2;
rxdataF128 += 4;
rxdataF_comp128 += 2;
}
}
Nre = (pilots == 0) ? 12 : 8;
precoded_signal_strength += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * Nre],
(nb_rb * Nre))) - (measurements->n0_power[aarx]));
// rx_antennas
}
measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength, measurements->n0_power_tot);
//printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
// measurements->precoded_cqi_dB[eNB_id][0]);
#endif
_mm_empty();
_m_empty();
}
void precode_channel_est(int32_t **dl_ch_estimates_ext,
LTE_DL_FRAME_PARMS *frame_parms,
LTE_UE_PDSCH *pdsch_vars,
unsigned char symbol,
unsigned short nb_rb,
MIMO_mode_t mimo_mode)
{
unsigned short rb;
__m128i *dl_ch0_128, *dl_ch1_128;
unsigned char aarx = 0, symbol_mod, pilots = 0;
unsigned char *pmi_ext = pdsch_vars->pmi_ext;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
pilots = 1;
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12]; // this is h11
dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12]; // this is h12
for(rb = 0; rb < nb_rb; rb++)
{
if(mimo_mode == LARGE_CDD)
{
prec2A_TM3_128(&dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM3_128(&dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM3_128(&dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODING1)
{
prec2A_TM4_128(0, &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(0, &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(0, &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODINGj)
{
prec2A_TM4_128(1, &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(1, &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(1, &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_PUSCH_PRECODING)
{
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else
{
LOG_E(PHY, "Unknown MIMO mode\n");
return;
}
if(pilots == 0)
{
dl_ch0_128 += 3;
dl_ch1_128 += 3;
}
else
{
dl_ch0_128 += 2;
dl_ch1_128 += 2;
}
}
}
}
void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms,
LTE_UE_PDSCH *pdsch_vars,
PHY_MEASUREMENTS *measurements,
int eNB_id,
unsigned char symbol,
unsigned char mod_order0,
unsigned char mod_order1,
int harq_pid,
int round,
MIMO_mode_t mimo_mode,
unsigned short nb_rb,
unsigned short mmse_flag,
unsigned char output_shift0,
unsigned char output_shift1)
{
#if defined(__x86_64__) || defined(__i386__)
unsigned short rb, Nre;
__m128i *dl_ch0_128, *dl_ch1_128, *dl_ch_mag0_128, *dl_ch_mag1_128, *dl_ch_mag0_128b, *dl_ch_mag1_128b, *rxdataF128, *rxdataF_comp0_128, *rxdataF_comp1_128;
unsigned char aarx = 0, symbol_mod, pilots = 0;
int precoded_signal_strength0 = 0, precoded_signal_strength1 = 0;
int rx_power_correction;
int **rxdataF_ext = pdsch_vars->rxdataF_ext;
int **dl_ch_estimates_ext = pdsch_vars->dl_ch_estimates_ext;
int **dl_ch_mag0 = pdsch_vars->dl_ch_mag0;
int **dl_ch_mag1 = pdsch_vars->dl_ch_mag1[harq_pid][round];
int **dl_ch_magb0 = pdsch_vars->dl_ch_magb0;
int **dl_ch_magb1 = pdsch_vars->dl_ch_magb1[harq_pid][round];
int **rxdataF_comp0 = pdsch_vars->rxdataF_comp0;
int **rxdataF_comp1 = pdsch_vars->rxdataF_comp1[harq_pid][round];
unsigned char *pmi_ext = pdsch_vars->pmi_ext;
__m128i mmtmpD0, mmtmpD1, mmtmpD2, mmtmpD3, QAM_amp0_128, QAM_amp1_128;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
pilots = 1;
}
rx_power_correction = 1;
// printf("comp prec: symbol %d, pilots %d\n",symbol, pilots);
__m128i QAM_amp0_128b = _mm_setzero_si128();
if(mod_order0 == 4)
{
QAM_amp0_128 = _mm_set1_epi16(QAM16_n1);
}
else if(mod_order0 == 6)
{
QAM_amp0_128 = _mm_set1_epi16(QAM64_n1);
QAM_amp0_128b = _mm_set1_epi16(QAM64_n2);
}
__m128i QAM_amp1_128b = _mm_setzero_si128();
if(mod_order1 == 4)
{
QAM_amp1_128 = _mm_set1_epi16(QAM16_n1);
}
else if(mod_order1 == 6)
{
QAM_amp1_128 = _mm_set1_epi16(QAM64_n1);
QAM_amp1_128b = _mm_set1_epi16(QAM64_n2);
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12]; // this is h11
dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12]; // this is h12
dl_ch_mag0_128 = (__m128i *)&dl_ch_mag0[aarx][symbol * frame_parms->N_RB_DL * 12]; //responsible for x1
dl_ch_mag0_128b = (__m128i *)&dl_ch_magb0[aarx][symbol * frame_parms->N_RB_DL * 12]; //responsible for x1
dl_ch_mag1_128 = (__m128i *)&dl_ch_mag1[aarx][symbol * frame_parms->N_RB_DL * 12]; //responsible for x2. always coming from tx2
dl_ch_mag1_128b = (__m128i *)&dl_ch_magb1[aarx][symbol * frame_parms->N_RB_DL * 12]; //responsible for x2. always coming from tx2
rxdataF128 = (__m128i *)&rxdataF_ext[aarx][symbol * frame_parms->N_RB_DL * 12]; //received signal on antenna of interest h11*x1+h12*x2
rxdataF_comp0_128 = (__m128i *)&rxdataF_comp0[aarx][symbol * frame_parms->N_RB_DL * 12]; //result of multipl with MF x1 on antenna of interest
rxdataF_comp1_128 = (__m128i *)&rxdataF_comp1[aarx][symbol * frame_parms->N_RB_DL * 12]; //result of multipl with MF x2 on antenna of interest
for(rb = 0; rb < nb_rb; rb++)
{
if(mmse_flag == 0)
{
// combine TX channels using precoder from pmi
if(mimo_mode == LARGE_CDD)
{
prec2A_TM3_128(&dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM3_128(&dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM3_128(&dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODING1)
{
prec2A_TM4_128(0, &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(0, &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(0, &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODINGj)
{
prec2A_TM4_128(1, &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(1, &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(1, &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_PUSCH_PRECODING)
{
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else
{
LOG_E(PHY, "Unknown MIMO mode\n");
return;
}
}
if(mod_order0 > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0], dl_ch0_128[0]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift0);
mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1], dl_ch0_128[1]);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift0);
mmtmpD0 = _mm_packs_epi32(mmtmpD0, mmtmpD1);
dl_ch_mag0_128[0] = _mm_unpacklo_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag0_128b[0] = dl_ch_mag0_128[0];
dl_ch_mag0_128[0] = _mm_mulhi_epi16(dl_ch_mag0_128[0], QAM_amp0_128);
dl_ch_mag0_128[0] = _mm_slli_epi16(dl_ch_mag0_128[0], 1);
// print_shorts("dl_ch_mag0_128[0]=",&dl_ch_mag0_128[0]);
dl_ch_mag0_128[1] = _mm_unpackhi_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag0_128b[1] = dl_ch_mag0_128[1];
dl_ch_mag0_128[1] = _mm_mulhi_epi16(dl_ch_mag0_128[1], QAM_amp0_128);
dl_ch_mag0_128[1] = _mm_slli_epi16(dl_ch_mag0_128[1], 1);
if(pilots == 0)
{
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2], dl_ch0_128[2]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift0);
mmtmpD1 = _mm_packs_epi32(mmtmpD0, mmtmpD0);
dl_ch_mag0_128[2] = _mm_unpacklo_epi16(mmtmpD1, mmtmpD1);
dl_ch_mag0_128b[2] = dl_ch_mag0_128[2];
dl_ch_mag0_128[2] = _mm_mulhi_epi16(dl_ch_mag0_128[2], QAM_amp0_128);
dl_ch_mag0_128[2] = _mm_slli_epi16(dl_ch_mag0_128[2], 1);
}
dl_ch_mag0_128b[0] = _mm_mulhi_epi16(dl_ch_mag0_128b[0], QAM_amp0_128b);
dl_ch_mag0_128b[0] = _mm_slli_epi16(dl_ch_mag0_128b[0], 1);
// print_shorts("dl_ch_mag0_128b[0]=",&dl_ch_mag0_128b[0]);
dl_ch_mag0_128b[1] = _mm_mulhi_epi16(dl_ch_mag0_128b[1], QAM_amp0_128b);
dl_ch_mag0_128b[1] = _mm_slli_epi16(dl_ch_mag0_128b[1], 1);
if(pilots == 0)
{
dl_ch_mag0_128b[2] = _mm_mulhi_epi16(dl_ch_mag0_128b[2], QAM_amp0_128b);
dl_ch_mag0_128b[2] = _mm_slli_epi16(dl_ch_mag0_128b[2], 1);
}
}
if(mod_order1 > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = _mm_madd_epi16(dl_ch1_128[0], dl_ch1_128[0]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift1);
mmtmpD1 = _mm_madd_epi16(dl_ch1_128[1], dl_ch1_128[1]);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift1);
mmtmpD0 = _mm_packs_epi32(mmtmpD0, mmtmpD1);
dl_ch_mag1_128[0] = _mm_unpacklo_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag1_128b[0] = dl_ch_mag1_128[0];
dl_ch_mag1_128[0] = _mm_mulhi_epi16(dl_ch_mag1_128[0], QAM_amp1_128);
dl_ch_mag1_128[0] = _mm_slli_epi16(dl_ch_mag1_128[0], 1);
// print_shorts("dl_ch_mag1_128[0]=",&dl_ch_mag1_128[0]);
dl_ch_mag1_128[1] = _mm_unpackhi_epi16(mmtmpD0, mmtmpD0);
dl_ch_mag1_128b[1] = dl_ch_mag1_128[1];
dl_ch_mag1_128[1] = _mm_mulhi_epi16(dl_ch_mag1_128[1], QAM_amp1_128);
dl_ch_mag1_128[1] = _mm_slli_epi16(dl_ch_mag1_128[1], 1);
if(pilots == 0)
{
mmtmpD0 = _mm_madd_epi16(dl_ch1_128[2], dl_ch1_128[2]);
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift1);
mmtmpD1 = _mm_packs_epi32(mmtmpD0, mmtmpD0);
dl_ch_mag1_128[2] = _mm_unpacklo_epi16(mmtmpD1, mmtmpD1);
dl_ch_mag1_128b[2] = dl_ch_mag1_128[2];
dl_ch_mag1_128[2] = _mm_mulhi_epi16(dl_ch_mag1_128[2], QAM_amp1_128);
dl_ch_mag1_128[2] = _mm_slli_epi16(dl_ch_mag1_128[2], 1);
}
dl_ch_mag1_128b[0] = _mm_mulhi_epi16(dl_ch_mag1_128b[0], QAM_amp1_128b);
dl_ch_mag1_128b[0] = _mm_slli_epi16(dl_ch_mag1_128b[0], 1);
// print_shorts("dl_ch_mag1_128b[0]=",&dl_ch_mag1_128b[0]);
dl_ch_mag1_128b[1] = _mm_mulhi_epi16(dl_ch_mag1_128b[1], QAM_amp1_128b);
dl_ch_mag1_128b[1] = _mm_slli_epi16(dl_ch_mag1_128b[1], 1);
if(pilots == 0)
{
dl_ch_mag1_128b[2] = _mm_mulhi_epi16(dl_ch_mag1_128b[2], QAM_amp1_128b);
dl_ch_mag1_128b[2] = _mm_slli_epi16(dl_ch_mag1_128b[2], 1);
}
}
// layer 0
// MF multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0], rxdataF128[0]);
// print_ints("re",&mmtmpD0);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[0]);
// print_ints("im",&mmtmpD1);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift0);
// printf("Shift: %d\n",output_shift);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift0);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
rxdataF_comp0_128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128);
// print_shorts("ch:",dl_ch0_128);
//print_shorts("pack:",rxdataF_comp0_128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1], rxdataF128[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift0);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp0_128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+1);
// print_shorts("ch:",dl_ch0_128+1);
// print_shorts("pack:",rxdataF_comp0_128+1);
if(pilots == 0)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2], rxdataF128[2]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[2]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift0);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp0_128[2] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+2);
// print_shorts("ch:",dl_ch0_128+2);
// print_shorts("pack:",rxdataF_comp0_128+2);
}
// layer 1
// MF multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch1_128[0], rxdataF128[0]);
// print_ints("re",&mmtmpD0);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
// print_ints("im",&mmtmpD1);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[0]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift1);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift1);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
rxdataF_comp1_128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128);
// print_shorts("ch:",dl_ch1_128);
// print_shorts("pack:",rxdataF_comp1_128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch1_128[1], rxdataF128[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift1);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp1_128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+1);
// print_shorts("ch:",dl_ch1_128+1);
// print_shorts("pack:",rxdataF_comp1_128+1);
if(pilots == 0)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch1_128[2], rxdataF128[2]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[2], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, rxdataF128[2]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift1);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
rxdataF_comp1_128[2] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rx:",rxdataF128+2);
// print_shorts("ch:",dl_ch1_128+2);
// print_shorts("pack:",rxdataF_comp1_128+2);
dl_ch0_128 += 3;
dl_ch1_128 += 3;
dl_ch_mag0_128 += 3;
dl_ch_mag1_128 += 3;
dl_ch_mag0_128b += 3;
dl_ch_mag1_128b += 3;
rxdataF128 += 3;
rxdataF_comp0_128 += 3;
rxdataF_comp1_128 += 3;
}
else
{
dl_ch0_128 += 2;
dl_ch1_128 += 2;
dl_ch_mag0_128 += 2;
dl_ch_mag1_128 += 2;
dl_ch_mag0_128b += 2;
dl_ch_mag1_128b += 2;
rxdataF128 += 2;
rxdataF_comp0_128 += 2;
rxdataF_comp1_128 += 2;
}
} // rb loop
Nre = (pilots == 0) ? 12 : 8;
precoded_signal_strength0 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * Nre],
(nb_rb * Nre)) * rx_power_correction) - (measurements->n0_power[aarx]));
precoded_signal_strength1 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx + 2][symbol * frame_parms->N_RB_DL * Nre],
(nb_rb * Nre)) * rx_power_correction) - (measurements->n0_power[aarx]));
} // rx_antennas
measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength0, measurements->n0_power_tot);
measurements->precoded_cqi_dB[eNB_id][1] = dB_fixed2(precoded_signal_strength1, measurements->n0_power_tot);
// printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol,
// measurements->precoded_cqi_dB[eNB_id][0]);
_mm_empty();
_m_empty();
#elif defined(__arm__)
unsigned short rb, Nre;
unsigned char aarx, symbol_mod, pilots = 0;
int precoded_signal_strength0 = 0, precoded_signal_strength1 = 0, rx_power_correction;
int16x4_t *dl_ch0_128, *rxdataF128;
int16x4_t *dl_ch1_128;
int16x8_t *dl_ch0_128b, *dl_ch1_128b;
int32x4_t mmtmpD0, mmtmpD1, mmtmpD0b, mmtmpD1b;
int16x8_t *dl_ch_mag0_128, *dl_ch_mag0_128b, *dl_ch_mag1_128, *dl_ch_mag1_128b, mmtmpD2, mmtmpD3, mmtmpD4, *rxdataF_comp0_128, *rxdataF_comp1_128;
int16x8_t QAM_amp0_128, QAM_amp0_128b, QAM_amp1_128, QAM_amp1_128b;
int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift);
int **rxdataF_ext = pdsch_vars->rxdataF_ext;
int **dl_ch_estimates_ext = pdsch_vars->dl_ch_estimates_ext;
int **dl_ch_mag0 = pdsch_vars->dl_ch_mag0;
int **dl_ch_mag1 = pdsch_vars->dl_ch_mag1[harq_pid][round];
int **dl_ch_magb0 = pdsch_vars->dl_ch_magb0;
int **dl_ch_magb1 = pdsch_vars->dl_ch_magb1[harq_pid][round];
int **rxdataF_comp0 = pdsch_vars->rxdataF_comp0;
int **rxdataF_comp1 = pdsch_vars->rxdataF_comp1[harq_pid][round];
int16_t conj[4]__attribute__((aligned(16))) = {1, -1, 1, -1};
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
if(frame_parms->nb_antenna_ports_eNB == 1) // 10 out of 12 so don't reduce size
{
nb_rb = 1 + (5 * nb_rb / 6);
}
else
{
pilots = 1;
}
}
rx_power_correction = 1;
if(mod_order0 == 4)
{
QAM_amp0_128 = vmovq_n_s16(QAM16_n1); // 2/sqrt(10)
QAM_amp0_128b = vmovq_n_s16(0);
}
else if(mod_order0 == 6)
{
QAM_amp0_128 = vmovq_n_s16(QAM64_n1); //
QAM_amp0_128b = vmovq_n_s16(QAM64_n2);
}
if(mod_order1 == 4)
{
QAM_amp1_128 = vmovq_n_s16(QAM16_n1); // 2/sqrt(10)
QAM_amp1_128b = vmovq_n_s16(0);
}
else if(mod_order1 == 6)
{
QAM_amp1_128 = vmovq_n_s16(QAM64_n1); //
QAM_amp1_128b = vmovq_n_s16(QAM64_n2);
}
// printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol);
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch0_128 = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch1_128 = (int16x4_t *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch0_128b = (int16x8_t *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch1_128b = (int16x8_t *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag0_128 = (int16x8_t *)&dl_ch_mag0[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag0_128b = (int16x8_t *)&dl_ch_magb0[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag1_128 = (int16x8_t *)&dl_ch_mag1[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag1_128b = (int16x8_t *)&dl_ch_magb1[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF128 = (int16x4_t *)&rxdataF_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp0_128 = (int16x8_t *)&rxdataF_comp0[aarx][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp1_128 = (int16x8_t *)&rxdataF_comp1[aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
if(mmse_flag == 0)
{
// combine TX channels using precoder from pmi
if(mimo_mode == LARGE_CDD)
{
prec2A_TM3_128(&dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM3_128(&dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM3_128(&dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODING1)
{
prec2A_TM4_128(0, &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(0, &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(0, &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODINGj)
{
prec2A_TM4_128(1, &dl_ch0_128[0], &dl_ch1_128[0]);
prec2A_TM4_128(1, &dl_ch0_128[1], &dl_ch1_128[1]);
if(pilots == 0)
{
prec2A_TM4_128(1, &dl_ch0_128[2], &dl_ch1_128[2]);
}
}
else
{
LOG_E(PHY, "Unknown MIMO mode\n");
return;
}
}
if(mod_order0 > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = vmull_s16(dl_ch0_128[0], dl_ch0_128[0]);
// mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3];
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
// mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits
mmtmpD1 = vmull_s16(dl_ch0_128[1], dl_ch0_128[1]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
// mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits
mmtmpD0 = vmull_s16(dl_ch0_128[2], dl_ch0_128[2]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch0_128[3], dl_ch0_128[3]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
if(pilots == 0)
{
mmtmpD0 = vmull_s16(dl_ch0_128[4], dl_ch0_128[4]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch0_128[5], dl_ch0_128[5]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
}
dl_ch_mag0_128b[0] = vqdmulhq_s16(mmtmpD2, QAM_amp0_128b);
dl_ch_mag0_128b[1] = vqdmulhq_s16(mmtmpD3, QAM_amp0_128b);
dl_ch_mag0_128[0] = vqdmulhq_s16(mmtmpD2, QAM_amp0_128);
dl_ch_mag0_128[1] = vqdmulhq_s16(mmtmpD3, QAM_amp0_128);
if(pilots == 0)
{
dl_ch_mag0_128b[2] = vqdmulhq_s16(mmtmpD4, QAM_amp0_128b);
dl_ch_mag0_128[2] = vqdmulhq_s16(mmtmpD4, QAM_amp0_128);
}
}
if(mod_order1 > 2)
{
// get channel amplitude if not QPSK
mmtmpD0 = vmull_s16(dl_ch1_128[0], dl_ch1_128[0]);
// mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3];
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
// mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits
mmtmpD1 = vmull_s16(dl_ch1_128[1], dl_ch1_128[1]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
// mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits
mmtmpD0 = vmull_s16(dl_ch1_128[2], dl_ch1_128[2]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch1_128[3], dl_ch1_128[3]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
if(pilots == 0)
{
mmtmpD0 = vmull_s16(dl_ch1_128[4], dl_ch1_128[4]);
mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0, vrev64q_s32(mmtmpD0)), output_shift128);
mmtmpD1 = vmull_s16(dl_ch1_128[5], dl_ch1_128[5]);
mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1, vrev64q_s32(mmtmpD1)), output_shift128);
mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
}
dl_ch_mag1_128b[0] = vqdmulhq_s16(mmtmpD2, QAM_amp1_128b);
dl_ch_mag1_128b[1] = vqdmulhq_s16(mmtmpD3, QAM_amp1_128b);
dl_ch_mag1_128[0] = vqdmulhq_s16(mmtmpD2, QAM_amp1_128);
dl_ch_mag1_128[1] = vqdmulhq_s16(mmtmpD3, QAM_amp1_128);
if(pilots == 0)
{
dl_ch_mag1_128b[2] = vqdmulhq_s16(mmtmpD4, QAM_amp1_128b);
dl_ch_mag1_128[2] = vqdmulhq_s16(mmtmpD4, QAM_amp1_128);
}
}
mmtmpD0 = vmull_s16(dl_ch0_128[0], rxdataF128[0]);
//mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])]
mmtmpD1 = vmull_s16(dl_ch0_128[1], rxdataF128[1]);
//mmtmpD1 = [Re(ch[2])Re(rx[2]) Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3]) Im(ch[3])Im(ch[3])]
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
//mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])]
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0], *(int16x4_t *)conj)), rxdataF128[0]);
//mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])]
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1], *(int16x4_t *)conj)), rxdataF128[1]);
//mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
//mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp0_128[0] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
mmtmpD0 = vmull_s16(dl_ch0_128[2], rxdataF128[2]);
mmtmpD1 = vmull_s16(dl_ch0_128[3], rxdataF128[3]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2], *(int16x4_t *)conj)), rxdataF128[2]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3], *(int16x4_t *)conj)), rxdataF128[3]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp0_128[1] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
// second stream
mmtmpD0 = vmull_s16(dl_ch1_128[0], rxdataF128[0]);
mmtmpD1 = vmull_s16(dl_ch1_128[1], rxdataF128[1]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0], *(int16x4_t *)conj)), rxdataF128[0]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1], *(int16x4_t *)conj)), rxdataF128[1]);
//mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])]
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
//mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])]
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp1_128[0] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
mmtmpD0 = vmull_s16(dl_ch1_128[2], rxdataF128[2]);
mmtmpD1 = vmull_s16(dl_ch1_128[3], rxdataF128[3]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2], *(int16x4_t *)conj)), rxdataF128[2]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3], *(int16x4_t *)conj)), rxdataF128[3]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp1_128[1] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
if(pilots == 0)
{
mmtmpD0 = vmull_s16(dl_ch0_128[4], rxdataF128[4]);
mmtmpD1 = vmull_s16(dl_ch0_128[5], rxdataF128[5]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4], *(int16x4_t *)conj)), rxdataF128[4]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5], *(int16x4_t *)conj)), rxdataF128[5]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp0_128[2] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
mmtmpD0 = vmull_s16(dl_ch1_128[4], rxdataF128[4]);
mmtmpD1 = vmull_s16(dl_ch1_128[5], rxdataF128[5]);
mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0), vget_high_s32(mmtmpD0)),
vpadd_s32(vget_low_s32(mmtmpD1), vget_high_s32(mmtmpD1)));
mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[4], *(int16x4_t *)conj)), rxdataF128[4]);
mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[5], *(int16x4_t *)conj)), rxdataF128[5]);
mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b), vget_high_s32(mmtmpD0b)),
vpadd_s32(vget_low_s32(mmtmpD1b), vget_high_s32(mmtmpD1b)));
mmtmpD0 = vqshlq_s32(mmtmpD0, output_shift128);
mmtmpD1 = vqshlq_s32(mmtmpD1, output_shift128);
rxdataF_comp1_128[2] = vcombine_s16(vmovn_s32(mmtmpD0), vmovn_s32(mmtmpD1));
}
}
Nre = (pilots == 0) ? 12 : 8;
// rx_antennas
}
Nre = (pilots == 0) ? 12 : 8;
precoded_signal_strength0 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * Nre],
(nb_rb * Nre)) * rx_power_correction) - (measurements->n0_power[aarx]));
precoded_signal_strength1 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx + 2][symbol * frame_parms->N_RB_DL * Nre],
(nb_rb * Nre)) * rx_power_correction) - (measurements->n0_power[aarx]));
measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength0, measurements->n0_power_tot);
measurements->precoded_cqi_dB[eNB_id][1] = dB_fixed2(precoded_signal_strength1, measurements->n0_power_tot);
#endif
}
void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms,
unsigned char symbol,
unsigned short nb_rb,
int **dl_ch_estimates_ext,
int **dl_ch_estimates_ext_i,
int **dl_ch_rho_ext,
unsigned char output_shift)
{
#if defined(__x86_64__)||defined(__i386__)
unsigned short rb;
__m128i *dl_ch128, *dl_ch128i, *dl_ch_rho128, mmtmpD0, mmtmpD1, mmtmpD2, mmtmpD3;
unsigned char aarx, symbol_mod, pilots = 0;
// printf("dlsch_dual_stream_correlation: symbol %d\n",symbol);
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
pilots = 1;
}
// printf("Dual stream correlation (%p)\n",dl_ch_estimates_ext_i);
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
if(dl_ch_estimates_ext_i == NULL) // TM3/4
{
dl_ch128i = (__m128i *)&dl_ch_estimates_ext[aarx + frame_parms->nb_antennas_rx][symbol * frame_parms->N_RB_DL * 12];
}
else
{
dl_ch128i = (__m128i *)&dl_ch_estimates_ext_i[aarx][symbol * frame_parms->N_RB_DL * 12];
}
dl_ch_rho128 = (__m128i *)&dl_ch_rho_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[0], dl_ch128i[0]);
// print_ints("re",&mmtmpD0);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)&conjugate[0]);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128i[0]);
// print_ints("im",&mmtmpD1);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
// print_ints("re(shift)",&mmtmpD0);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
// print_ints("im(shift)",&mmtmpD1);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
// print_ints("c0",&mmtmpD2);
// print_ints("c1",&mmtmpD3);
dl_ch_rho128[0] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
// print_shorts("rho 0:",dl_ch_rho128);
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[1], dl_ch128i[1]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128i[1]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
dl_ch_rho128[1] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
if(pilots == 0)
{
// multiply by conjugated channel
mmtmpD0 = _mm_madd_epi16(dl_ch128[2], dl_ch128i[2]);
// mmtmpD0 contains real part of 4 consecutive outputs (32-bit)
mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2], _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1, _MM_SHUFFLE(2, 3, 0, 1));
mmtmpD1 = _mm_sign_epi16(mmtmpD1, *(__m128i *)conjugate);
mmtmpD1 = _mm_madd_epi16(mmtmpD1, dl_ch128i[2]);
// mmtmpD1 contains imag part of 4 consecutive outputs (32-bit)
mmtmpD0 = _mm_srai_epi32(mmtmpD0, output_shift);
mmtmpD1 = _mm_srai_epi32(mmtmpD1, output_shift);
mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0, mmtmpD1);
mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0, mmtmpD1);
dl_ch_rho128[2] = _mm_packs_epi32(mmtmpD2, mmtmpD3);
dl_ch128 += 3;
dl_ch128i += 3;
dl_ch_rho128 += 3;
}
else
{
dl_ch128 += 2;
dl_ch128i += 2;
dl_ch_rho128 += 2;
}
}
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
#endif
}
void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms,
int **rxdataF_comp,
int **rxdataF_comp_i,
int **rho,
int **rho_i,
int **dl_ch_mag,
int **dl_ch_magb,
int **dl_ch_mag_i,
int **dl_ch_magb_i,
unsigned char symbol,
unsigned short nb_rb,
unsigned char dual_stream_UE)
{
#if defined(__x86_64__)||defined(__i386__)
unsigned char aatx;
int i;
__m128i *rxdataF_comp128_0, *rxdataF_comp128_1, *rxdataF_comp128_i0, *rxdataF_comp128_i1, *dl_ch_mag128_0, *dl_ch_mag128_1, *dl_ch_mag128_0b, *dl_ch_mag128_1b, *rho128_0, *rho128_1, *rho128_i0, *rho128_i1,
*dl_ch_mag128_i0, *dl_ch_mag128_i1, *dl_ch_mag128_i0b, *dl_ch_mag128_i1b;
if(frame_parms->nb_antennas_rx > 1)
{
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
{
rxdataF_comp128_0 = (__m128i *)&rxdataF_comp[(aatx << 1)][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_1 = (__m128i *)&rxdataF_comp[(aatx << 1) + 1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_0 = (__m128i *)&dl_ch_mag[(aatx << 1)][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_1 = (__m128i *)&dl_ch_mag[(aatx << 1) + 1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_0b = (__m128i *)&dl_ch_magb[(aatx << 1)][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_1b = (__m128i *)&dl_ch_magb[(aatx << 1) + 1][symbol * frame_parms->N_RB_DL * 12];
// MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation)
for(i = 0; i < nb_rb * 3; i++)
{
rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i], 1), _mm_srai_epi16(rxdataF_comp128_1[i], 1));
dl_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i], 1), _mm_srai_epi16(dl_ch_mag128_1[i], 1));
dl_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i], 1), _mm_srai_epi16(dl_ch_mag128_1b[i], 1));
// print_shorts("mrc comp0:",&rxdataF_comp128_0[i]);
// print_shorts("mrc mag0:",&dl_ch_mag128_0[i]);
// print_shorts("mrc mag0b:",&dl_ch_mag128_0b[i]);
// print_shorts("mrc rho1:",&rho128_1[i]);
}
}
if(rho)
{
rho128_0 = (__m128i *) &rho[0][symbol * frame_parms->N_RB_DL * 12];
rho128_1 = (__m128i *) &rho[1][symbol * frame_parms->N_RB_DL * 12];
for(i = 0; i < nb_rb * 3; i++)
{
// print_shorts("mrc rho0:",&rho128_0[i]);
// print_shorts("mrc rho1:",&rho128_1[i]);
rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i], 1), _mm_srai_epi16(rho128_1[i], 1));
}
}
if(dual_stream_UE == 1)
{
rho128_i0 = (__m128i *) &rho_i[0][symbol * frame_parms->N_RB_DL * 12];
rho128_i1 = (__m128i *) &rho_i[1][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_i0 = (__m128i *)&rxdataF_comp_i[0][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_i1 = (__m128i *)&rxdataF_comp_i[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i0 = (__m128i *)&dl_ch_mag_i[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i1 = (__m128i *)&dl_ch_mag_i[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i0b = (__m128i *)&dl_ch_magb_i[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i1b = (__m128i *)&dl_ch_magb_i[1][symbol * frame_parms->N_RB_DL * 12];
for(i = 0; i < nb_rb * 3; i++)
{
rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i], 1), _mm_srai_epi16(rxdataF_comp128_i1[i], 1));
rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i], 1), _mm_srai_epi16(rho128_i1[i], 1));
dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i], 1), _mm_srai_epi16(dl_ch_mag128_i1[i], 1));
dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i], 1), _mm_srai_epi16(dl_ch_mag128_i1b[i], 1));
}
}
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
unsigned char aatx;
int i;
int16x8_t *rxdataF_comp128_0, *rxdataF_comp128_1, *rxdataF_comp128_i0, *rxdataF_comp128_i1, *dl_ch_mag128_0, *dl_ch_mag128_1, *dl_ch_mag128_0b, *dl_ch_mag128_1b, *rho128_0, *rho128_1, *rho128_i0, *rho128_i1,
*dl_ch_mag128_i0, *dl_ch_mag128_i1, *dl_ch_mag128_i0b, *dl_ch_mag128_i1b;
if(frame_parms->nb_antennas_rx > 1)
{
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
{
rxdataF_comp128_0 = (int16x8_t *)&rxdataF_comp[(aatx << 1)][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_1 = (int16x8_t *)&rxdataF_comp[(aatx << 1) + 1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_0 = (int16x8_t *)&dl_ch_mag[(aatx << 1)][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_1 = (int16x8_t *)&dl_ch_mag[(aatx << 1) + 1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_0b = (int16x8_t *)&dl_ch_magb[(aatx << 1)][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_1b = (int16x8_t *)&dl_ch_magb[(aatx << 1) + 1][symbol * frame_parms->N_RB_DL * 12];
// MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation)
for(i = 0; i < nb_rb * 3; i++)
{
rxdataF_comp128_0[i] = vhaddq_s16(rxdataF_comp128_0[i], rxdataF_comp128_1[i]);
dl_ch_mag128_0[i] = vhaddq_s16(dl_ch_mag128_0[i], dl_ch_mag128_1[i]);
dl_ch_mag128_0b[i] = vhaddq_s16(dl_ch_mag128_0b[i], dl_ch_mag128_1b[i]);
}
}
if(rho)
{
rho128_0 = (int16x8_t *) &rho[0][symbol * frame_parms->N_RB_DL * 12];
rho128_1 = (int16x8_t *) &rho[1][symbol * frame_parms->N_RB_DL * 12];
for(i = 0; i < nb_rb * 3; i++)
{
// print_shorts("mrc rho0:",&rho128_0[i]);
// print_shorts("mrc rho1:",&rho128_1[i]);
rho128_0[i] = vhaddq_s16(rho128_0[i], rho128_1[i]);
}
}
if(dual_stream_UE == 1)
{
rho128_i0 = (int16x8_t *) &rho_i[0][symbol * frame_parms->N_RB_DL * 12];
rho128_i1 = (int16x8_t *) &rho_i[1][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_i0 = (int16x8_t *)&rxdataF_comp_i[0][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_i1 = (int16x8_t *)&rxdataF_comp_i[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i0 = (int16x8_t *)&dl_ch_mag_i[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i1 = (int16x8_t *)&dl_ch_mag_i[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i0b = (int16x8_t *)&dl_ch_magb_i[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i1b = (int16x8_t *)&dl_ch_magb_i[1][symbol * frame_parms->N_RB_DL * 12];
for(i = 0; i < nb_rb * 3; i++)
{
rxdataF_comp128_i0[i] = vhaddq_s16(rxdataF_comp128_i0[i], rxdataF_comp128_i1[i]);
rho128_i0[i] = vhaddq_s16(rho128_i0[i], rho128_i1[i]);
dl_ch_mag128_i0[i] = vhaddq_s16(dl_ch_mag128_i0[i], dl_ch_mag128_i1[i]);
dl_ch_mag128_i0b[i] = vhaddq_s16(dl_ch_mag128_i0b[i], dl_ch_mag128_i1b[i]);
}
}
}
#endif
}
void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms,
LTE_UE_PDSCH *pdsch_vars,
int harq_pid,
int round,
unsigned char symbol,
unsigned short nb_rb,
unsigned char dual_stream_UE)
{
int i;
__m128i *rxdataF_comp128_0, *rxdataF_comp128_1;
__m128i *dl_ch_mag128_0, *dl_ch_mag128_1;
__m128i *dl_ch_mag128_0b, *dl_ch_mag128_1b;
__m128i *rho128_0, *rho128_1;
int **rxdataF_comp0 = pdsch_vars->rxdataF_comp0;
int **rxdataF_comp1 = pdsch_vars->rxdataF_comp1[harq_pid][round];
int **dl_ch_rho_ext = pdsch_vars->dl_ch_rho_ext[harq_pid][round]; //for second stream
int **dl_ch_rho2_ext = pdsch_vars->dl_ch_rho2_ext;
int **dl_ch_mag0 = pdsch_vars->dl_ch_mag0;
int **dl_ch_mag1 = pdsch_vars->dl_ch_mag1[harq_pid][round];
int **dl_ch_magb0 = pdsch_vars->dl_ch_magb0;
int **dl_ch_magb1 = pdsch_vars->dl_ch_magb1[harq_pid][round];
rxdataF_comp128_0 = (__m128i *)&rxdataF_comp0[0][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_1 = (__m128i *)&rxdataF_comp0[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_0 = (__m128i *)&dl_ch_mag0[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_1 = (__m128i *)&dl_ch_mag0[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_0b = (__m128i *)&dl_ch_magb0[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_1b = (__m128i *)&dl_ch_magb0[1][symbol * frame_parms->N_RB_DL * 12];
rho128_0 = (__m128i *) &dl_ch_rho2_ext[0][symbol * frame_parms->N_RB_DL * 12];
rho128_1 = (__m128i *) &dl_ch_rho2_ext[1][symbol * frame_parms->N_RB_DL * 12];
// MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation)
for(i = 0; i < nb_rb * 3; i++)
{
rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i], 1), _mm_srai_epi16(rxdataF_comp128_1[i], 1));
dl_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i], 1), _mm_srai_epi16(dl_ch_mag128_1[i], 1));
dl_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i], 1), _mm_srai_epi16(dl_ch_mag128_1b[i], 1));
rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i], 1), _mm_srai_epi16(rho128_1[i], 1));
if(frame_parms->nb_antennas_rx > 2)
{
__m128i *rxdataF_comp128_2 = NULL;
__m128i *rxdataF_comp128_3 = NULL;
__m128i *dl_ch_mag128_2 = NULL;
__m128i *dl_ch_mag128_3 = NULL;
__m128i *dl_ch_mag128_2b = NULL;
__m128i *dl_ch_mag128_3b = NULL;
__m128i *rho128_2 = NULL;
__m128i *rho128_3 = NULL;
rxdataF_comp128_2 = (__m128i *)&rxdataF_comp0[2][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_3 = (__m128i *)&rxdataF_comp0[3][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_2 = (__m128i *)&dl_ch_mag0[2][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_3 = (__m128i *)&dl_ch_mag0[3][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_2b = (__m128i *)&dl_ch_magb0[2][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_3b = (__m128i *)&dl_ch_magb0[3][symbol * frame_parms->N_RB_DL * 12];
rho128_2 = (__m128i *) &dl_ch_rho2_ext[2][symbol * frame_parms->N_RB_DL * 12];
rho128_3 = (__m128i *) &dl_ch_rho2_ext[3][symbol * frame_parms->N_RB_DL * 12];
/*rxdataF_comp*/
rxdataF_comp128_2[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_2[i], 1), _mm_srai_epi16(rxdataF_comp128_3[i], 1));
rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i], 1), _mm_srai_epi16(rxdataF_comp128_2[i], 1));
/*dl_ch_mag*/
dl_ch_mag128_2[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_2[i], 1), _mm_srai_epi16(dl_ch_mag128_3[i], 1));
dl_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i], 1), _mm_srai_epi16(dl_ch_mag128_2[i], 1));
/*dl_ch_mag*/
dl_ch_mag128_2b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_2b[i], 1), _mm_srai_epi16(dl_ch_mag128_3b[i], 1));
dl_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i], 1), _mm_srai_epi16(dl_ch_mag128_2b[i], 1));
/*rho*/
rho128_2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_2[i], 1), _mm_srai_epi16(rho128_3[i], 1));
rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i], 1), _mm_srai_epi16(rho128_2[i], 1));
}
}
if(dual_stream_UE == 1)
{
__m128i *dl_ch_mag128_i0, *dl_ch_mag128_i1;
__m128i *dl_ch_mag128_i0b, *dl_ch_mag128_i1b;
__m128i *rho128_i0, *rho128_i1;
__m128i *rxdataF_comp128_i0, *rxdataF_comp128_i1;
rxdataF_comp128_i0 = (__m128i *)&rxdataF_comp1[0][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_i1 = (__m128i *)&rxdataF_comp1[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i0 = (__m128i *)&dl_ch_mag1[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i1 = (__m128i *)&dl_ch_mag1[1][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i0b = (__m128i *)&dl_ch_magb1[0][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i1b = (__m128i *)&dl_ch_magb1[1][symbol * frame_parms->N_RB_DL * 12];
rho128_i0 = (__m128i *) &dl_ch_rho_ext[0][symbol * frame_parms->N_RB_DL * 12];
rho128_i1 = (__m128i *) &dl_ch_rho_ext[1][symbol * frame_parms->N_RB_DL * 12];
for(i = 0; i < nb_rb * 3; i++)
{
rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i], 1), _mm_srai_epi16(rxdataF_comp128_i1[i], 1));
dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i], 1), _mm_srai_epi16(dl_ch_mag128_i1[i], 1));
dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i], 1), _mm_srai_epi16(dl_ch_mag128_i1b[i], 1));
rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i], 1), _mm_srai_epi16(rho128_i1[i], 1));
if(frame_parms->nb_antennas_rx > 2)
{
__m128i *rxdataF_comp128_i2 = NULL;
__m128i *rxdataF_comp128_i3 = NULL;
__m128i *dl_ch_mag128_i2 = NULL;
__m128i *dl_ch_mag128_i3 = NULL;
__m128i *dl_ch_mag128_i2b = NULL;
__m128i *dl_ch_mag128_i3b = NULL;
__m128i *rho128_i2 = NULL;
__m128i *rho128_i3 = NULL;
rxdataF_comp128_i2 = (__m128i *)&rxdataF_comp1[2][symbol * frame_parms->N_RB_DL * 12];
rxdataF_comp128_i3 = (__m128i *)&rxdataF_comp1[3][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i2 = (__m128i *)&dl_ch_mag1[2][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i3 = (__m128i *)&dl_ch_mag1[3][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i2b = (__m128i *)&dl_ch_magb1[2][symbol * frame_parms->N_RB_DL * 12];
dl_ch_mag128_i3b = (__m128i *)&dl_ch_magb1[3][symbol * frame_parms->N_RB_DL * 12];
rho128_i2 = (__m128i *) &dl_ch_rho_ext[2][symbol * frame_parms->N_RB_DL * 12];
rho128_i3 = (__m128i *) &dl_ch_rho_ext[3][symbol * frame_parms->N_RB_DL * 12];
/*rxdataF_comp*/
rxdataF_comp128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i2[i], 1), _mm_srai_epi16(rxdataF_comp128_i3[i], 1));
rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i], 1), _mm_srai_epi16(rxdataF_comp128_i2[i], 1));
/*dl_ch_mag*/
dl_ch_mag128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2[i], 1), _mm_srai_epi16(dl_ch_mag128_i3[i], 1));
dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i], 1), _mm_srai_epi16(dl_ch_mag128_i2[i], 1));
/*dl_ch_mag*/
dl_ch_mag128_i2b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2b[i], 1), _mm_srai_epi16(dl_ch_mag128_i3b[i], 1));
dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i], 1), _mm_srai_epi16(dl_ch_mag128_i2b[i], 1));
/*rho*/
rho128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i2[i], 1), _mm_srai_epi16(rho128_i3[i], 1));
rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i], 1), _mm_srai_epi16(rho128_i2[i], 1));
}
}
}
_mm_empty();
_m_empty();
}
void dlsch_scale_channel(int **dl_ch_estimates_ext,
LTE_DL_FRAME_PARMS *frame_parms,
LTE_UE_DLSCH_t **dlsch_ue,
uint8_t symbol,
unsigned short nb_rb)
{
#if defined(__x86_64__)||defined(__i386__)
short rb, ch_amp;
unsigned char aatx, aarx, pilots = 0, symbol_mod;
__m128i *dl_ch128, ch_amp128;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
if(frame_parms->nb_antenna_ports_eNB == 1) // 10 out of 12 so don't reduce size
{
nb_rb = 1 + (5 * nb_rb / 6);
}
else
{
pilots = 1;
}
}
// Determine scaling amplitude based the symbol
ch_amp = ((pilots) ? (dlsch_ue[0]->sqrt_rho_b) : (dlsch_ue[0]->sqrt_rho_a));
LOG_D(PHY, "Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n", symbol_mod, ch_amp, pilots, nb_rb, frame_parms->Ncp, symbol);
// printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp);
ch_amp128 = _mm_set1_epi16(ch_amp); // Q3.13
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
{
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[(aatx << 1) + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
dl_ch128[0] = _mm_mulhi_epi16(dl_ch128[0], ch_amp128);
dl_ch128[0] = _mm_slli_epi16(dl_ch128[0], 3);
dl_ch128[1] = _mm_mulhi_epi16(dl_ch128[1], ch_amp128);
dl_ch128[1] = _mm_slli_epi16(dl_ch128[1], 3);
if(pilots)
{
dl_ch128 += 2;
}
else
{
dl_ch128[2] = _mm_mulhi_epi16(dl_ch128[2], ch_amp128);
dl_ch128[2] = _mm_slli_epi16(dl_ch128[2], 3);
dl_ch128 += 3;
}
}
}
}
#elif defined(__arm__)
#endif
}
//compute average channel_level on each (TX,RX) antenna pair
void dlsch_channel_level(int **dl_ch_estimates_ext,
LTE_DL_FRAME_PARMS *frame_parms,
int32_t *avg,
uint8_t symbol,
unsigned short nb_rb)
{
#if defined(__x86_64__)||defined(__i386__)
//printf("symbol = %d\n", symbol);
short rb;
unsigned char aatx, aarx, nre = 12, symbol_mod;
__m128i *dl_ch128, avg128D;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
nre = 8;
}
else if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB == 1))
{
nre = 10;
}
else
{
nre = 12;
}
//nb_rb*nre = y * 2^x
int16_t x = factor2(nb_rb * nre);
int16_t y = (nb_rb * nre) >> x;
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
//clear average level
//printf("aatx = %d, aarx = %d, aatx*frame_parms->nb_antennas_rx + aarx] = %d \n", aatx, aarx, aatx*frame_parms->nb_antennas_rx + aarx);
avg128D = _mm_setzero_si128();
// 5 is always a symbol with no pilots for both normal and extended prefix
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx * 2 + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
//printf("rb %d : ",rb);
avg128D = _mm_add_epi32(avg128D, _mm_srai_epi32(_mm_madd_epi16(dl_ch128[0], dl_ch128[0]), x));
avg128D = _mm_add_epi32(avg128D, _mm_srai_epi32(_mm_madd_epi16(dl_ch128[1], dl_ch128[1]), x));
//avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch128[0],_mm_srai_epi16(_mm_mulhi_epi16(dl_ch128[0], coeff128),15)));
//avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch128[1],_mm_srai_epi16(_mm_mulhi_epi16(dl_ch128[1], coeff128),15)));
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
dl_ch128 += 2;
}
else
{
avg128D = _mm_add_epi32(avg128D, _mm_srai_epi32(_mm_madd_epi16(dl_ch128[2], dl_ch128[2]), x));
//avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch128[2],_mm_srai_epi16(_mm_mulhi_epi16(dl_ch128[2], coeff128),15)));
dl_ch128 += 3;
}
/* if(rb==0){
print_shorts("dl_ch128",&dl_ch128[0]);
print_shorts("dl_ch128",&dl_ch128[1]);
print_shorts("dl_ch128",&dl_ch128[2]);
}*/
}
avg[aatx * frame_parms->nb_antennas_rx + aarx] = (((int32_t *)&avg128D)[0] +
((int32_t *)&avg128D)[1] +
((int32_t *)&avg128D)[2] +
((int32_t *)&avg128D)[3]) / y;
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
short rb;
unsigned char aatx, aarx, nre = 12, symbol_mod;
int32x4_t avg128D;
int16x4_t *dl_ch128;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
//clear average level
avg128D = vdupq_n_s32(0);
// 5 is always a symbol with no pilots for both normal and extended prefix
dl_ch128 = (int16x4_t *)&dl_ch_estimates_ext[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
// printf("rb %d : ",rb);
// print_shorts("ch",&dl_ch128[0]);
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[0], dl_ch128[0]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[1], dl_ch128[1]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[2], dl_ch128[2]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[3], dl_ch128[3]));
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->mode1_flag == 0))
{
dl_ch128 += 4;
}
else
{
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[4], dl_ch128[4]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[5], dl_ch128[5]));
dl_ch128 += 6;
}
/*
if (rb==0) {
print_shorts("dl_ch128",&dl_ch128[0]);
print_shorts("dl_ch128",&dl_ch128[1]);
print_shorts("dl_ch128",&dl_ch128[2]);
}
*/
}
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->mode1_flag == 0))
{
nre = 8;
}
else if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->mode1_flag == 1))
{
nre = 10;
}
else
{
nre = 12;
}
avg[aatx * frame_parms->nb_antennas_rx + aarx] = (((int32_t *)&avg128D)[0] +
((int32_t *)&avg128D)[1] +
((int32_t *)&avg128D)[2] +
((int32_t *)&avg128D)[3]) / (nb_rb * nre);
//printf("Channel level : %d\n",avg[aatx*(frame_parms->nb_antennas_rx-1) + aarx]);
}
#endif
}
void dlsch_channel_level_core(int **dl_ch_estimates_ext,
int32_t *avg,
int n_tx,
int n_rx,
int length,
int start_point)
{
#if defined(__x86_64__)||defined(__i386__)
short ii;
int aatx, aarx;
int length_mod8;
int length2;
__m128i *dl_ch128, avg128D;
int16_t x = factor2(length);
int16_t y = (length) >> x;
for(aatx = 0; aatx < n_tx; aatx++)
for(aarx = 0; aarx < n_rx; aarx++)
{
avg128D = _mm_setzero_si128();
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx * 2 + aarx][start_point];
length_mod8 = length & 7;
if(length_mod8 == 0)
{
length2 = length >> 3;
for(ii = 0; ii < length2; ii++)
{
avg128D = _mm_add_epi32(avg128D, _mm_srai_epi32(_mm_madd_epi16(dl_ch128[0], dl_ch128[0]), x));
avg128D = _mm_add_epi32(avg128D, _mm_srai_epi32(_mm_madd_epi16(dl_ch128[1], dl_ch128[1]), x));
dl_ch128 += 2;
}
}
else
{
printf("Channel level: Received number of subcarriers is not multiple of 4, \n"
"need to adapt the code!\n");
}
avg[aatx * n_rx + aarx] = (((int32_t *)&avg128D)[0] +
((int32_t *)&avg128D)[1] +
((int32_t *)&avg128D)[2] +
((int32_t *)&avg128D)[3]) / y;
//printf("Channel level [%d]: %d\n",aatx*n_rx + aarx, avg[aatx*n_rx + aarx]);
}
_mm_empty();
_m_empty();
/* FIXME This part needs to be adapted like the one above */
#elif defined(__arm__)
short rb;
unsigned char aatx, aarx, nre = 12, symbol_mod;
int32x4_t avg128D;
int16x4_t *dl_ch128;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
//clear average level
avg128D = vdupq_n_s32(0);
// 5 is always a symbol with no pilots for both normal and extended prefix
dl_ch128 = (int16x4_t *)&dl_ch_estimates_ext[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
// printf("rb %d : ",rb);
// print_shorts("ch",&dl_ch128[0]);
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[0], dl_ch128[0]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[1], dl_ch128[1]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[2], dl_ch128[2]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[3], dl_ch128[3]));
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
dl_ch128 += 4;
}
else
{
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[4], dl_ch128[4]));
avg128D = vqaddq_s32(avg128D, vmull_s16(dl_ch128[5], dl_ch128[5]));
dl_ch128 += 6;
}
}
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
nre = 8;
}
else if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB == 1))
{
nre = 10;
}
else
{
nre = 12;
}
avg[aatx * frame_parms->nb_antennas_rx + aarx] = (((int32_t *)&avg128D)[0] +
((int32_t *)&avg128D)[1] +
((int32_t *)&avg128D)[2] +
((int32_t *)&avg128D)[3]) / (nb_rb * nre);
//printf("Channel level : %d\n",avg[aatx*(frame_parms->nb_antennas_rx-1) + aarx]);
}
#endif
}
void dlsch_channel_level_median(int **dl_ch_estimates_ext,
int32_t *median,
int n_tx,
int n_rx,
int length,
int start_point)
{
#if defined(__x86_64__)||defined(__i386__)
short ii;
int aatx, aarx;
int length2;
int max = 0, min = 0;
int norm_pack;
__m128i *dl_ch128, norm128D;
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
max = 0;
min = 0;
norm128D = _mm_setzero_si128();
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx * 2 + aarx][start_point];
length2 = length >> 2;
for(ii = 0; ii < length2; ii++)
{
norm128D = _mm_srai_epi32(_mm_madd_epi16(dl_ch128[0], dl_ch128[0]), 1);
//print_ints("norm128D",&norm128D[0]);
norm_pack = ((int32_t *)&norm128D)[0] +
((int32_t *)&norm128D)[1] +
((int32_t *)&norm128D)[2] +
((int32_t *)&norm128D)[3];
if(norm_pack > max)
{
max = norm_pack;
}
if(norm_pack < min)
{
min = norm_pack;
}
dl_ch128 += 1;
}
median[aatx * n_rx + aarx] = (max + min) >> 1;
// printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]);
}
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
short rb;
unsigned char aatx, aarx, nre = 12, symbol_mod;
int32x4_t norm128D;
int16x4_t *dl_ch128;
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
{
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
max = 0;
min = 0;
norm128D = vdupq_n_s32(0);
dl_ch128 = (int16x4_t *)&dl_ch_estimates_ext[aatx * n_rx + aarx][start_point];
length_mod8 = length & 3;
length2 = length >> 2;
for(ii = 0; ii < length2; ii++)
{
norm128D = vshrq_n_u32(vmull_s16(dl_ch128[0], dl_ch128[0]), 1);
norm_pack = ((int32_t *)&norm128D)[0] +
((int32_t *)&norm128D)[1] +
((int32_t *)&norm128D)[2] +
((int32_t *)&norm128D)[3];
if(norm_pack > max)
{
max = norm_pack;
}
if(norm_pack < min)
{
min = norm_pack;
}
dl_ch128 += 1;
}
median[aatx * n_rx + aarx] = (max + min) >> 1;
//printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]);
}
}
#endif
}
void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars,
LTE_DL_FRAME_PARMS *frame_parms,
PHY_MEASUREMENTS *measurements,
unsigned char first_symbol_flag,
MIMO_mode_t mimo_mode,
unsigned short mmse_flag,
int noise_power,
unsigned char symbol,
unsigned short nb_rb)
{
int **rxdataF_ext = pdsch_vars->rxdataF_ext;
int **dl_ch_estimates_ext = pdsch_vars->dl_ch_estimates_ext;
unsigned char *pmi_ext = pdsch_vars->pmi_ext;
int avg_00[frame_parms->nb_antenna_ports_eNB * frame_parms->nb_antennas_rx];
int avg_01[frame_parms->nb_antenna_ports_eNB * frame_parms->nb_antennas_rx];
int symbol_mod, length, start_point, nre;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
nre = 8;
}
else if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB == 1))
{
nre = 10;
}
else
{
nre = 12;
}
length = nre * nb_rb;
start_point = symbol * nb_rb * 12;
mmse_processing_core(rxdataF_ext,
dl_ch_estimates_ext,
noise_power,
frame_parms->nb_antenna_ports_eNB,
frame_parms->nb_antennas_rx,
length,
start_point);
/* dlsch_channel_aver_band(dl_ch_estimates_ext,
frame_parms,
chan_avg,
symbol,
nb_rb);
for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++)
for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) {
H[aatx*frame_parms->nb_antennas_rx + aarx] = (float)(chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r/(32768.0)) + I*(float)(chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i/(32768.0));
// printf("H [%d] = (%f, %f) \n", aatx*frame_parms->nb_antennas_rx + aarx, creal(H[aatx*frame_parms->nb_antennas_rx + aarx]), cimag(H[aatx*frame_parms->nb_antennas_rx + aarx]));
}*/
if(first_symbol_flag == 1)
{
dlsch_channel_level_TM34(dl_ch_estimates_ext,
frame_parms,
pmi_ext,
avg_00,
avg_01,
symbol,
nb_rb,
mmse_flag,
mimo_mode);
avg_00[0] = (log2_approx(avg_00[0]) / 2) + dlsch_demod_shift + 4; // + 2 ;//+ 4;
avg_01[0] = (log2_approx(avg_01[0]) / 2) + dlsch_demod_shift + 4; // + 2 ;//+ 4;
pdsch_vars->log2_maxh0 = cmax(avg_00[0], 0);
pdsch_vars->log2_maxh1 = cmax(avg_01[0], 0);
}
}
void mmse_processing_core(int32_t **rxdataF_ext,
int32_t **dl_ch_estimates_ext,
int noise_power,
int n_tx,
int n_rx,
int length,
int start_point)
{
int aatx, aarx, re;
float imag;
float real;
float complex **W_MMSE = malloc(n_tx * n_rx * sizeof(float complex *));
for(int j = 0; j < n_tx * n_rx; j++)
{
W_MMSE[j] = malloc(sizeof(float complex) * length);
}
float complex *H = malloc(n_tx * n_rx * sizeof(float complex));
float complex *W_MMSE_re = malloc(n_tx * n_rx * sizeof(float complex));
float complex **dl_ch_estimates_ext_flcpx = malloc(n_tx * n_rx * sizeof(float complex *));
for(int j = 0; j < n_tx * n_rx; j++)
{
dl_ch_estimates_ext_flcpx[j] = malloc(sizeof(float complex) * length);
}
float complex **rxdataF_ext_flcpx = malloc(n_rx * sizeof(float complex *));
for(int j = 0; j < n_rx; j++)
{
rxdataF_ext_flcpx[j] = malloc(sizeof(float complex) * length);
}
chan_est_to_float(dl_ch_estimates_ext,
dl_ch_estimates_ext_flcpx,
n_tx,
n_rx,
length,
start_point);
for(re = 0; re < length; re++)
{
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
imag = cimag(dl_ch_estimates_ext_flcpx[aatx * n_rx + aarx][re]);
real = creal(dl_ch_estimates_ext_flcpx[aatx * n_rx + aarx][re]);
H[aatx * n_rx + aarx] = real + I * imag;
}
}
compute_MMSE(H, n_tx, noise_power, W_MMSE_re);
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
W_MMSE[aatx * n_rx + aarx][re] = W_MMSE_re[aatx * n_rx + aarx];
}
}
}
rxdataF_to_float(rxdataF_ext,
rxdataF_ext_flcpx,
n_rx,
length,
start_point);
mult_mmse_rxdataF(W_MMSE,
rxdataF_ext_flcpx,
n_tx,
n_rx,
length,
start_point);
mult_mmse_chan_est(W_MMSE,
dl_ch_estimates_ext_flcpx,
n_tx,
n_rx,
length,
start_point);
float_to_rxdataF(rxdataF_ext,
rxdataF_ext_flcpx,
n_tx,
n_rx,
length,
start_point);
float_to_chan_est(dl_ch_estimates_ext,
dl_ch_estimates_ext_flcpx,
n_tx,
n_rx,
length,
start_point);
free(W_MMSE);
free(H);
free(W_MMSE_re);
free(dl_ch_estimates_ext_flcpx);
free(rxdataF_ext_flcpx);
}
/*THIS FUNCTION TAKES FLOAT_POINT INPUT. SHOULD NOT BE USED WITH OAI*/
void mmse_processing_core_flp(float complex **rxdataF_ext_flcpx,
float complex **H,
int32_t **rxdataF_ext,
int32_t **dl_ch_estimates_ext,
float noise_power,
int n_tx,
int n_rx,
int length,
int start_point)
{
int aatx, aarx, re;
float max = 0;
float one_over_max = 0;
float complex **W_MMSE = malloc(n_tx * n_rx * sizeof(float complex *));
for(int j = 0; j < n_tx * n_rx; j++)
{
W_MMSE[j] = malloc(sizeof(float complex) * length);
}
float complex *H_re = malloc(n_tx * n_rx * sizeof(float complex));
float complex *W_MMSE_re = malloc(n_tx * n_rx * sizeof(float complex));
for(re = 0; re < length; re++)
{
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
H_re[aatx * n_rx + aarx] = H[aatx * n_rx + aarx][re];
#ifdef DEBUG_MMSE
if(re == 0)
{
printf(" H_re[%d]= (%f + i%f)\n", aatx * n_rx + aarx, creal(H_re[aatx * n_rx + aarx]), cimag(H_re[aatx * n_rx + aarx]));
}
#endif
}
}
compute_MMSE(H_re, n_tx, noise_power, W_MMSE_re);
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
W_MMSE[aatx * n_rx + aarx][re] = W_MMSE_re[aatx * n_rx + aarx];
if(fabs(creal(W_MMSE_re[aatx * n_rx + aarx])) > max)
{
max = fabs(creal(W_MMSE_re[aatx * n_rx + aarx]));
}
if(fabs(cimag(W_MMSE_re[aatx * n_rx + aarx])) > max)
{
max = fabs(cimag(W_MMSE_re[aatx * n_rx + aarx]));
}
}
}
}
one_over_max = 1.0 / max;
for(re = 0; re < length; re++)
for(aatx = 0; aatx < n_tx; aatx++)
for(aarx = 0; aarx < n_rx; aarx++)
{
#ifdef DEBUG_MMSE
if(re == 0)
{
printf(" W_MMSE[%d] = (%f + i%f)\n", aatx * n_rx + aarx, creal(W_MMSE[aatx * n_rx + aarx][re]), cimag(W_MMSE[aatx * n_rx + aarx][re]));
}
#endif
W_MMSE[aatx * n_rx + aarx][re] = one_over_max * W_MMSE[aatx * n_rx + aarx][re];
#ifdef DEBUG_MMSE
if(re == 0)
{
printf(" AFTER NORM W_MMSE[%d] = (%f + i%f), max = %f \n", aatx * n_rx + aarx, creal(W_MMSE[aatx * n_rx + aarx][re]), cimag(W_MMSE[aatx * n_rx + aarx][re]), max);
}
#endif
}
mult_mmse_rxdataF(W_MMSE,
rxdataF_ext_flcpx,
n_tx,
n_rx,
length,
start_point);
mult_mmse_chan_est(W_MMSE,
H,
n_tx,
n_rx,
length,
start_point);
float_to_rxdataF(rxdataF_ext,
rxdataF_ext_flcpx,
n_tx,
n_rx,
length,
start_point);
float_to_chan_est(dl_ch_estimates_ext,
H,
n_tx,
n_rx,
length,
start_point);
free(H_re);
free(W_MMSE);
free(W_MMSE_re);
}
void dlsch_channel_aver_band(int **dl_ch_estimates_ext,
LTE_DL_FRAME_PARMS *frame_parms,
struct complex32 *chan_avg,
unsigned char symbol,
unsigned short nb_rb)
{
#if defined(__x86_64__)||defined(__i386__)
short rb;
unsigned char aatx, aarx, nre = 12, symbol_mod;
__m128i *dl_ch128, avg128D;
int32_t chan_est_avg[4];
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
nre = 8;
}
else if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB == 1))
{
nre = 10;
}
else
{
nre = 12;
}
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
{
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
avg128D = _mm_setzero_si128();
// print_shorts("avg128D 1",&avg128D);
for(rb = 0; rb < nb_rb; rb++)
{
/* printf("symbol %d, ant %d, nre*nrb %d, rb %d \n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, nb_rb*nre, rb);
print_shorts("aver dl_ch128",&dl_ch128[0]);
print_shorts("aver dl_ch128",&dl_ch128[1]);
print_shorts("aver dl_ch128",&dl_ch128[2]);
avg128D = _mm_add_epi16(avg128D, dl_ch128[0]);*/
//print_shorts("avg128D 2",&avg128D);
avg128D = _mm_add_epi16(avg128D, dl_ch128[1]);
// print_shorts("avg128D 3",&avg128D);
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
dl_ch128 += 2;
}
else
{
avg128D = _mm_add_epi16(avg128D, dl_ch128[2]);
// print_shorts("avg128D 4",&avg128D);
dl_ch128 += 3;
}
}
chan_avg[aatx * frame_parms->nb_antennas_rx + aarx].r = (((int16_t *)&avg128D)[0] +
((int16_t *)&avg128D)[2] +
((int16_t *)&avg128D)[4] +
((int16_t *)&avg128D)[6]) / (nb_rb * nre);
// printf("symb %d chan_avg re [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r);
chan_avg[aatx * frame_parms->nb_antennas_rx + aarx].i = (((int16_t *)&avg128D)[1] +
((int16_t *)&avg128D)[3] +
((int16_t *)&avg128D)[5] +
((int16_t *)&avg128D)[7]) / (nb_rb * nre);
// printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i);
//printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i);
chan_est_avg[aatx * frame_parms->nb_antennas_rx + aarx] = (((int32_t)chan_avg[aatx * frame_parms->nb_antennas_rx + aarx].i) << 16) | (((int32_t)chan_avg[aatx * frame_parms->nb_antennas_rx + aarx].r) & 0xffff);
//printf("symb %d chan_est_avg [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]);
dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx * frame_parms->nb_antennas_rx + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
dl_ch128[0] = _mm_set1_epi32(chan_est_avg[aatx * frame_parms->nb_antennas_rx + aarx]);
dl_ch128[1] = _mm_set1_epi32(chan_est_avg[aatx * frame_parms->nb_antennas_rx + aarx]);
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
dl_ch128 += 2;
}
else
{
dl_ch128[2] = _mm_set1_epi32(chan_est_avg[aatx * frame_parms->nb_antennas_rx + aarx]);
dl_ch128 += 3;
}
}
}
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
#endif
}
void rxdataF_to_float(int32_t **rxdataF_ext,
float complex **rxdataF_f,
int n_rx,
int length,
int start_point)
{
short re;
int aarx;
int16_t imag;
int16_t real;
for(aarx = 0; aarx < n_rx; aarx++)
{
for(re = 0; re < length; re++)
{
imag = (int16_t)(rxdataF_ext[aarx][start_point + re] >> 16);
real = (int16_t)(rxdataF_ext[aarx][start_point + re] & 0xffff);
rxdataF_f[aarx][re] = (float)(real / (32768.0)) + I * (float)(imag / (32768.0));
#ifdef DEBUG_MMSE
if(re == 0)
{
printf("rxdataF_to_float: aarx = %d, real= %d, imag = %d\n", aarx, real, imag);
//printf("rxdataF_to_float: rxdataF_ext[%d][%d] = %d\n", aarx, start_point + re, rxdataF_ext[aarx][start_point + re]);
//printf("rxdataF_to_float: ant %d, re = %d, rxdataF_f real = %f, rxdataF_f imag = %f \n", aarx, re, creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re]));
}
#endif
}
}
}
void chan_est_to_float(int32_t **dl_ch_estimates_ext,
float complex **dl_ch_estimates_ext_f,
int n_tx,
int n_rx,
int length,
int start_point)
{
short re;
int aatx, aarx;
int16_t imag;
int16_t real;
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
for(re = 0; re < length; re++)
{
imag = (int16_t)(dl_ch_estimates_ext[aatx * n_rx + aarx][start_point + re] >> 16);
real = (int16_t)(dl_ch_estimates_ext[aatx * n_rx + aarx][start_point + re] & 0xffff);
dl_ch_estimates_ext_f[aatx * n_rx + aarx][re] = (float)(real / (32768.0)) + I * (float)(imag / (32768.0));
#ifdef DEBUG_MMSE
if(re == 0)
{
printf("ant %d, re = %d, real = %d, imag = %d \n", aatx * n_rx + aarx, re, real, imag);
printf("ant %d, re = %d, real = %f, imag = %f \n", aatx * n_rx + aarx, re, creal(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]));
}
#endif
}
}
}
}
void float_to_chan_est(int32_t **dl_ch_estimates_ext,
float complex **dl_ch_estimates_ext_f,
int n_tx,
int n_rx,
int length,
int start_point)
{
short re;
int aarx, aatx;
int16_t imag;
int16_t real;
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
for(re = 0; re < length; re++)
{
if(cimag(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]) < -1)
{
imag = 0x8000;
}
else if(cimag(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]) >= 1)
{
imag = 0x7FFF;
}
else
{
imag = cimag(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]) * 32768;
}
if(creal(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]) < -1)
{
real = 0x8000;
}
else if(creal(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]) >= 1)
{
real = 0x7FFF;
}
else
{
real = creal(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]) * 32768;
}
dl_ch_estimates_ext[aatx * n_rx + aarx][start_point + re] = (((int32_t)imag) << 16) | ((int32_t)real & 0xffff);
#ifdef DEBUG_MMSE
if(re == 0)
{
printf(" float_to_chan_est: chan est real = %f, chan est imag = %f\n", creal(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]));
printf("float_to_chan_est: real fixed = %d, imag fixed = %d\n", real, imag);
printf("float_to_chan_est: ant %d, re = %d, dl_ch_estimates_ext = %d \n", aatx * n_rx + aarx, re, dl_ch_estimates_ext[aatx * n_rx + aarx][start_point + re]);
}
#endif
}
}
}
}
void float_to_rxdataF(int32_t **rxdataF_ext,
float complex **rxdataF_f,
int n_tx,
int n_rx,
int length,
int start_point)
{
short re;
int aarx;
int16_t imag;
int16_t real;
for(aarx = 0; aarx < n_rx; aarx++)
{
for(re = 0; re < length; re++)
{
if(cimag(rxdataF_f[aarx][re]) < -1)
{
imag = 0x8000;
}
else if(cimag(rxdataF_f[aarx][re]) >= 1)
{
imag = 0x7FFF;
}
else
{
imag = cimag(rxdataF_f[aarx][re]) * 32768;
}
if(creal(rxdataF_f[aarx][re]) < -1)
{
real = 0x8000;
}
else if(creal(rxdataF_f[aarx][re]) >= 1)
{
real = 0x7FFF;
}
else
{
real = creal(rxdataF_f[aarx][re]) * 32768;
}
rxdataF_ext[aarx][start_point + re] = (((int32_t)imag) << 16) | (((int32_t)real) & 0xffff);
#ifdef DEBUG_MMSE
if(re == 0)
{
printf(" float_to_rxdataF: real = %f, imag = %f\n", creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re]));
printf("float_to_rxdataF: real fixed = %d, imag fixed = %d\n", real, imag);
printf("float_to_rxdataF: ant %d, re = %d, rxdataF_ext = %d \n", aarx, re, rxdataF_ext[aarx][start_point + re]);
}
#endif
}
}
}
void mult_mmse_rxdataF(float complex **Wmmse,
float complex **rxdataF_ext_f,
int n_tx,
int n_rx,
int length,
int start_point)
{
short re;
int aarx, aatx;
float complex *rxdata_re = malloc(n_rx * sizeof(float complex));
float complex *rxdata_mmse_re = malloc(n_rx * sizeof(float complex));
float complex *Wmmse_re = malloc(n_tx * n_rx * sizeof(float complex));
for(re = 0; re < length; re++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
rxdata_re[aarx] = rxdataF_ext_f[aarx][re];
#ifdef DEBUG_MMSE
if(re == 0)
{
printf("mult_mmse_rxdataF before: rxdata_re[%d] = (%f, %f)\n", aarx, creal(rxdata_re[aarx]), cimag(rxdata_re[aarx]));
}
#endif
}
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
Wmmse_re[aatx * n_rx + aarx] = Wmmse[aatx * n_rx + aarx][re];
}
}
mutl_matrix_matrix_col_based(Wmmse_re, rxdata_re, n_rx, n_tx, n_rx, 1, rxdata_mmse_re);
for(aarx = 0; aarx < n_rx; aarx++)
{
rxdataF_ext_f[aarx][re] = rxdata_mmse_re[aarx];
#ifdef DEBUG_MMSE
if(re == 0)
{
printf("mult_mmse_rxdataF after: rxdataF_ext_f[%d] = (%f, %f)\n", aarx, creal(rxdataF_ext_f[aarx][re]), cimag(rxdataF_ext_f[aarx][re]));
}
#endif
}
}
free(rxdata_re);
free(rxdata_mmse_re);
free(Wmmse_re);
}
void mult_mmse_chan_est(float complex **Wmmse,
float complex **dl_ch_estimates_ext_f,
int n_tx,
int n_rx,
int length,
int start_point)
{
short re;
int aarx, aatx;
float complex *chan_est_re = malloc(n_tx * n_rx * sizeof(float complex));
float complex *chan_est_mmse_re = malloc(n_tx * n_rx * sizeof(float complex));
float complex *Wmmse_re = malloc(n_tx * n_rx * sizeof(float complex));
for(re = 0; re < length; re++)
{
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
chan_est_re[aatx * n_rx + aarx] = dl_ch_estimates_ext_f[aatx * n_rx + aarx][re];
Wmmse_re[aatx * n_rx + aarx] = Wmmse[aatx * n_rx + aarx][re];
#ifdef DEBUG_MMSE
if(re == 0)
{
printf("mult_mmse_chan_est: chan_est_re[%d] = (%f, %f)\n", aatx * n_rx + aarx, creal(chan_est_re[aatx * n_rx + aarx]), cimag(chan_est_re[aatx * n_rx + aarx]));
}
#endif
}
}
mutl_matrix_matrix_col_based(Wmmse_re, chan_est_re, n_rx, n_tx, n_rx, n_tx, chan_est_mmse_re);
for(aatx = 0; aatx < n_tx; aatx++)
{
for(aarx = 0; aarx < n_rx; aarx++)
{
dl_ch_estimates_ext_f[aatx * n_rx + aarx][re] = chan_est_mmse_re[aatx * n_rx + aarx];
#ifdef DEBUG_MMSE
if(re == 0)
{
printf("mult_mmse_chan_est: dl_ch_estimates_ext_f[%d][%d] = (%f, %f)\n", aatx * n_rx + aarx, re, creal(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx * n_rx + aarx][re]));
}
#endif
}
}
}
free(Wmmse_re);
free(chan_est_re);
free(chan_est_mmse_re);
}
//compute average channel_level of effective (precoded) channel
void dlsch_channel_level_TM34(int **dl_ch_estimates_ext,
LTE_DL_FRAME_PARMS *frame_parms,
unsigned char *pmi_ext,
int *avg_0,
int *avg_1,
uint8_t symbol,
unsigned short nb_rb,
unsigned int mmse_flag,
MIMO_mode_t mimo_mode)
{
#if defined(__x86_64__)||defined(__i386__)
short rb;
unsigned char aarx, nre = 12, symbol_mod;
__m128i *dl_ch0_128, *dl_ch1_128, dl_ch0_128_tmp, dl_ch1_128_tmp, avg_0_128D, avg_1_128D;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
//clear average level
// avg_0_128D = _mm_setzero_si128();
// avg_1_128D = _mm_setzero_si128();
avg_0[0] = 0;
avg_0[1] = 0;
avg_1[0] = 0;
avg_1[1] = 0;
// 5 is always a symbol with no pilots for both normal and extended prefix
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
nre = 8;
}
else if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB == 1))
{
nre = 10;
}
else
{
nre = 12;
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
avg_0_128D = _mm_setzero_si128();
avg_1_128D = _mm_setzero_si128();
for(rb = 0; rb < nb_rb; rb++)
{
// printf("rb %d : \n",rb);
//print_shorts("ch0\n",&dl_ch0_128[0]);
//print_shorts("ch1\n",&dl_ch1_128[0]);
dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[0]);
dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[0]);
if(mmse_flag == 0)
{
if(mimo_mode == LARGE_CDD)
{
prec2A_TM3_128(&dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODING1)
{
prec2A_TM4_128(0, &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODINGj)
{
prec2A_TM4_128(1, &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_PUSCH_PRECODING)
{
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
}
// mmtmpD0 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
avg_0_128D = _mm_add_epi32(avg_0_128D, _mm_madd_epi16(dl_ch0_128_tmp, dl_ch0_128_tmp));
avg_1_128D = _mm_add_epi32(avg_1_128D, _mm_madd_epi16(dl_ch1_128_tmp, dl_ch1_128_tmp));
dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[1]);
dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[1]);
if(mmse_flag == 0)
{
if(mimo_mode == LARGE_CDD)
{
prec2A_TM3_128(&dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODING1)
{
prec2A_TM4_128(0, &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODINGj)
{
prec2A_TM4_128(1, &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_PUSCH_PRECODING)
{
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
}
// mmtmpD1 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
avg_0_128D = _mm_add_epi32(avg_0_128D, _mm_madd_epi16(dl_ch0_128_tmp, dl_ch0_128_tmp));
avg_1_128D = _mm_add_epi32(avg_1_128D, _mm_madd_epi16(dl_ch1_128_tmp, dl_ch1_128_tmp));
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
dl_ch0_128 += 2;
dl_ch1_128 += 2;
}
else
{
dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[2]);
dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[2]);
if(mmse_flag == 0)
{
if(mimo_mode == LARGE_CDD)
{
prec2A_TM3_128(&dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODING1)
{
prec2A_TM4_128(0, &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_UNIFORM_PRECODINGj)
{
prec2A_TM4_128(1, &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
else if(mimo_mode == DUALSTREAM_PUSCH_PRECODING)
{
prec2A_TM4_128(pmi_ext[rb], &dl_ch0_128_tmp, &dl_ch1_128_tmp);
}
}
// mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
avg_1_128D = _mm_add_epi32(avg_1_128D, _mm_madd_epi16(dl_ch1_128_tmp, dl_ch1_128_tmp));
avg_0_128D = _mm_add_epi32(avg_0_128D, _mm_madd_epi16(dl_ch0_128_tmp, dl_ch0_128_tmp));
dl_ch0_128 += 3;
dl_ch1_128 += 3;
}
}
avg_0[aarx] = (((int *)&avg_0_128D)[0]) / (nb_rb * nre) +
(((int *)&avg_0_128D)[1]) / (nb_rb * nre) +
(((int *)&avg_0_128D)[2]) / (nb_rb * nre) +
(((int *)&avg_0_128D)[3]) / (nb_rb * nre);
// printf("From Chan_level aver stream 0 %d =%d\n", aarx, avg_0[aarx]);
avg_1[aarx] = (((int *)&avg_1_128D)[0]) / (nb_rb * nre) +
(((int *)&avg_1_128D)[1]) / (nb_rb * nre) +
(((int *)&avg_1_128D)[2]) / (nb_rb * nre) +
(((int *)&avg_1_128D)[3]) / (nb_rb * nre);
// printf("From Chan_level aver stream 1 %d =%d\n", aarx, avg_1[aarx]);
}
//avg_0[0] = max(avg_0[0],avg_0[1]);
//avg_1[0] = max(avg_1[0],avg_1[1]);
//avg_0[0]= max(avg_0[0], avg_1[0]);
avg_0[0] = avg_0[0] + avg_0[1];
// printf("From Chan_level aver stream 0 final =%d\n", avg_0[0]);
avg_1[0] = avg_1[0] + avg_1[1];
// printf("From Chan_level aver stream 1 final =%d\n", avg_1[0]);
avg_0[0] = min(avg_0[0], avg_1[0]);
avg_1[0] = avg_0[0];
_mm_empty();
_m_empty();
#elif defined(__arm__)
#endif
}
//compute average channel_level of effective (precoded) channel
void dlsch_channel_level_TM56(int **dl_ch_estimates_ext,
LTE_DL_FRAME_PARMS *frame_parms,
unsigned char *pmi_ext,
int *avg,
uint8_t symbol,
unsigned short nb_rb)
{
#if defined(__x86_64__)||defined(__i386__)
short rb;
unsigned char aarx, nre = 12, symbol_mod;
__m128i *dl_ch0_128, *dl_ch1_128, dl_ch0_128_tmp, dl_ch1_128_tmp, avg128D;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
//clear average level
avg128D = _mm_setzero_si128();
avg[0] = 0;
avg[1] = 0;
// 5 is always a symbol with no pilots for both normal and extended prefix
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
nre = 8;
}
else if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB == 1))
{
nre = 10;
}
else
{
nre = 12;
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol * frame_parms->N_RB_DL * 12];
dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2 + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[0]);
dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[0]);
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128_tmp, &dl_ch1_128_tmp);
// mmtmpD0 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
avg128D = _mm_add_epi32(avg128D, _mm_madd_epi16(dl_ch0_128_tmp, dl_ch0_128_tmp));
dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[1]);
dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[1]);
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128_tmp, &dl_ch1_128_tmp);
// mmtmpD1 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
avg128D = _mm_add_epi32(avg128D, _mm_madd_epi16(dl_ch0_128_tmp, dl_ch0_128_tmp));
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
dl_ch0_128 += 2;
dl_ch1_128 += 2;
}
else
{
dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[2]);
dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[2]);
prec2A_TM56_128(pmi_ext[rb], &dl_ch0_128_tmp, &dl_ch1_128_tmp);
// mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp);
avg128D = _mm_add_epi32(avg128D, _mm_madd_epi16(dl_ch0_128_tmp, dl_ch0_128_tmp));
dl_ch0_128 += 3;
dl_ch1_128 += 3;
}
}
avg[aarx] = (((int *)&avg128D)[0]) / (nb_rb * nre) +
(((int *)&avg128D)[1]) / (nb_rb * nre) +
(((int *)&avg128D)[2]) / (nb_rb * nre) +
(((int *)&avg128D)[3]) / (nb_rb * nre);
}
// choose maximum of the 2 effective channels
avg[0] = cmax(avg[0], avg[1]);
_mm_empty();
_m_empty();
#elif defined(__arm__)
#endif
}
//compute average channel_level for TM7
void dlsch_channel_level_TM7(int **dl_bf_ch_estimates_ext,
LTE_DL_FRAME_PARMS *frame_parms,
int *avg,
uint8_t symbol,
unsigned short nb_rb)
{
#if defined(__x86_64__)||defined(__i386__)
short rb;
unsigned char aatx, aarx, nre = 12, symbol_mod;
__m128i *dl_ch128, avg128D;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
for(aatx = 0; aatx < frame_parms->nb_antenna_ports_eNB; aatx++)
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
//clear average level
avg128D = _mm_setzero_si128();
// 5 is always a symbol with no pilots for both normal and extended prefix
dl_ch128 = (__m128i *)&dl_bf_ch_estimates_ext[(aatx << 1) + aarx][symbol * frame_parms->N_RB_DL * 12];
for(rb = 0; rb < nb_rb; rb++)
{
// printf("rb %d : ",rb);
// print_shorts("ch",&dl_ch128[0]);
avg128D = _mm_add_epi32(avg128D, _mm_madd_epi16(dl_ch128[0], dl_ch128[0]));
avg128D = _mm_add_epi32(avg128D, _mm_madd_epi16(dl_ch128[1], dl_ch128[1]));
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))) && (frame_parms->nb_antenna_ports_eNB != 1))
{
dl_ch128 += 2;
}
else
{
avg128D = _mm_add_epi32(avg128D, _mm_madd_epi16(dl_ch128[2], dl_ch128[2]));
dl_ch128 += 3;
}
/*
if (rb==0) {
print_shorts("dl_ch128",&dl_ch128[0]);
print_shorts("dl_ch128",&dl_ch128[1]);
print_shorts("dl_ch128",&dl_ch128[2]);
}
*/
}
if(((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp - 1))))
{
nre = 10;
}
else if((frame_parms->Ncp == 0) && (symbol == 3 || symbol == 6 || symbol == 9 || symbol == 12))
{
nre = 9;
}
else if((frame_parms->Ncp == 1) && (symbol == 4 || symbol == 7 || symbol == 9))
{
nre = 8;
}
else
{
nre = 12;
}
avg[(aatx << 1) + aarx] = (((int *)&avg128D)[0] +
((int *)&avg128D)[1] +
((int *)&avg128D)[2] +
((int *)&avg128D)[3]) / (nb_rb * nre);
// printf("Channel level : %d\n",avg[(aatx<<1)+aarx]);
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
#endif
}
//#define ONE_OVER_2_Q15 16384
void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms,
int **rxdataF_comp,
int **dl_ch_mag,
int **dl_ch_magb,
unsigned char symbol,
unsigned short nb_rb)
{
#if defined(__x86_64__)||defined(__i386__)
short *rxF0, *rxF1;
__m128i *ch_mag0, *ch_mag1, *ch_mag0b, *ch_mag1b, *rxF0_128;
unsigned char rb, re;
int jj = (symbol * frame_parms->N_RB_DL * 12);
uint8_t symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
uint8_t pilots = ((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp))) ? 1 : 0;
rxF0_128 = (__m128i *) &rxdataF_comp[0][jj];
//amp = _mm_set1_epi16(ONE_OVER_2_Q15);
// printf("Doing alamouti!\n");
rxF0 = (short *)&rxdataF_comp[0][jj]; //tx antenna 0 h0*y
rxF1 = (short *)&rxdataF_comp[2][jj]; //tx antenna 1 h1*y
ch_mag0 = (__m128i *)&dl_ch_mag[0][jj];
ch_mag1 = (__m128i *)&dl_ch_mag[2][jj];
ch_mag0b = (__m128i *)&dl_ch_magb[0][jj];
ch_mag1b = (__m128i *)&dl_ch_magb[2][jj];
for(rb = 0; rb < nb_rb; rb++)
{
for(re = 0; re < ((pilots == 0) ? 12 : 8); re += 2)
{
// Alamouti RX combining
// printf("Alamouti: symbol %d, rb %d, re %d: rxF0 (%d,%d,%d,%d), rxF1 (%d,%d,%d,%d)\n",symbol,rb,re,rxF0[0],rxF0[1],rxF0[2],rxF0[3],rxF1[0],rxF1[1],rxF1[2],rxF1[3]);
rxF0[0] = rxF0[0] + rxF1[2];
rxF0[1] = rxF0[1] - rxF1[3];
rxF0[2] = rxF0[2] - rxF1[0];
rxF0[3] = rxF0[3] + rxF1[1];
// printf("Alamouti: rxF0 after (%d,%d,%d,%d)\n",rxF0[0],rxF0[1],rxF0[2],rxF0[3]);
rxF0 += 4;
rxF1 += 4;
}
// compute levels for 16QAM or 64 QAM llr unit
ch_mag0[0] = _mm_adds_epi16(ch_mag0[0], ch_mag1[0]);
ch_mag0[1] = _mm_adds_epi16(ch_mag0[1], ch_mag1[1]);
ch_mag0b[0] = _mm_adds_epi16(ch_mag0b[0], ch_mag1b[0]);
ch_mag0b[1] = _mm_adds_epi16(ch_mag0b[1], ch_mag1b[1]);
// account for 1/sqrt(2) scaling at transmission
//ch_mag0[0] = _mm_srai_epi16(ch_mag0[0],1);
//ch_mag0[1] = _mm_srai_epi16(ch_mag0[1],1);
//ch_mag0b[0] = _mm_srai_epi16(ch_mag0b[0],1);
//ch_mag0b[1] = _mm_srai_epi16(ch_mag0b[1],1);
//rxF0_128[0] = _mm_mulhi_epi16(rxF0_128[0],amp);
//rxF0_128[0] = _mm_slli_epi16(rxF0_128[0],1);
//rxF0_128[1] = _mm_mulhi_epi16(rxF0_128[1],amp);
//rxF0_128[1] = _mm_slli_epi16(rxF0_128[1],1);
//rxF0_128[0] = _mm_srai_epi16(rxF0_128[0],1);
//rxF0_128[1] = _mm_srai_epi16(rxF0_128[1],1);
if(pilots == 0)
{
ch_mag0[2] = _mm_adds_epi16(ch_mag0[2], ch_mag1[2]);
ch_mag0b[2] = _mm_adds_epi16(ch_mag0b[2], ch_mag1b[2]);
//ch_mag0[2] = _mm_srai_epi16(ch_mag0[2],1);
//ch_mag0b[2] = _mm_srai_epi16(ch_mag0b[2],1);
//rxF0_128[2] = _mm_mulhi_epi16(rxF0_128[2],amp);
//rxF0_128[2] = _mm_slli_epi16(rxF0_128[2],1);
//rxF0_128[2] = _mm_srai_epi16(rxF0_128[2],1);
ch_mag0 += 3;
ch_mag1 += 3;
ch_mag0b += 3;
ch_mag1b += 3;
rxF0_128 += 3;
}
else
{
ch_mag0 += 2;
ch_mag1 += 2;
ch_mag0b += 2;
ch_mag1b += 2;
rxF0_128 += 2;
}
}
_mm_empty();
_m_empty();
#elif defined(__arm__)
#endif
}
//==============================================================================================
// Extraction functions
//==============================================================================================
unsigned short dlsch_extract_rbs_single(int **rxdataF,
int **dl_ch_estimates,
int **rxdataF_ext,
int **dl_ch_estimates_ext,
unsigned short pmi,
unsigned char *pmi_ext,
unsigned int *rb_alloc,
unsigned char symbol,
unsigned char subframe,
uint32_t high_speed_flag,
LTE_DL_FRAME_PARMS *frame_parms)
{
unsigned short rb, nb_rb = 0;
unsigned char rb_alloc_ind;
unsigned char i, aarx, l, nsymb, skip_half = 0, sss_symb, pss_symb = 0;
int *dl_ch0, *dl_ch0_ext, *rxF, *rxF_ext;
unsigned char symbol_mod, pilots = 0, j = 0, poffset = 0;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
pilots = ((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp))) ? 1 : 0;
l = symbol;
nsymb = (frame_parms->Ncp == NORMAL) ? 14 : 12;
if(frame_parms->frame_type == TDD) // TDD
{
sss_symb = nsymb - 1;
pss_symb = 2;
}
else
{
sss_symb = (nsymb >> 1) - 2;
pss_symb = (nsymb >> 1) - 1;
}
if(symbol_mod == (4 - frame_parms->Ncp))
{
poffset = 3;
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
if(high_speed_flag == 1)
{
dl_ch0 = &dl_ch_estimates[aarx][5 + (symbol * (frame_parms->ofdm_symbol_size))];
}
else
{
dl_ch0 = &dl_ch_estimates[aarx][5];
}
dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol * (frame_parms->N_RB_DL * 12)];
rxF_ext = &rxdataF_ext[aarx][symbol * (frame_parms->N_RB_DL * 12)];
rxF = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol * (frame_parms->ofdm_symbol_size)))];
if((frame_parms->N_RB_DL & 1) == 0) // even number of RBs
for(rb = 0; rb < frame_parms->N_RB_DL; rb++)
{
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// For second half of RBs skip DC carrier
if(rb == (frame_parms->N_RB_DL >> 1))
{
rxF = &rxdataF[aarx][(1 + (symbol * (frame_parms->ofdm_symbol_size)))];
//dl_ch0++;
}
// PBCH
if((subframe == 0) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= nsymb >> 1) && (l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == sss_symb))
{
rb_alloc_ind = 0;
}
if(frame_parms->frame_type == FDD)
{
//PSS
if(((subframe == 0) || (subframe == 5)) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
}
if((frame_parms->frame_type == TDD) &&
(subframe == 6)) //TDD Subframe 6
{
if((rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
}
if(rb_alloc_ind == 1)
{
*pmi_ext = (pmi >> ((rb >> 2) << 1)) & 3;
memcpy(dl_ch0_ext, dl_ch0, 12 * sizeof(int));
/*
printf("rb %d\n",rb);
for (i=0;i<12;i++)
printf("(%d %d)",((short *)dl_ch0)[i<<1],((short*)dl_ch0)[1+(i<<1)]);
printf("\n");
*/
if(pilots == 0)
{
for(i = 0; i < 12; i++)
{
rxF_ext[i] = rxF[i];
/*
printf("%d : (%d,%d)\n",(rxF+i-&rxdataF[aarx][( (symbol*(frame_parms->ofdm_symbol_size)))]),
((short*)&rxF[i])[0],((short*)&rxF[i])[1]);*/
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
else
{
j = 0;
for(i = 0; i < 12; i++)
{
if((i != (frame_parms->nushift + poffset)) &&
(i != ((frame_parms->nushift + poffset + 6) % 12)))
{
rxF_ext[j] = rxF[i];
// printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
dl_ch0_ext[j++] = dl_ch0[i];
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
}
}
dl_ch0 += 12;
rxF += 12;
}
else // Odd number of RBs
{
for(rb = 0; rb < frame_parms->N_RB_DL >> 1; rb++)
{
#ifdef DEBUG_DLSCH_DEMOD
printf("dlch_ext %u\n", dl_ch0_ext - &dl_ch_estimates_ext[aarx][0]);
#endif
skip_half = 0;
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// PBCH
if((subframe == 0) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3
if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 1;
}
else if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 2;
}
//SSS
if(((subframe == 0) || (subframe == 5)) &&
(rb > ((frame_parms->N_RB_DL >> 1) - 3)) &&
(rb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == sss_symb))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) &&
(rb == ((frame_parms->N_RB_DL >> 1) - 3)) &&
(l == sss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) &&
(rb == ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == sss_symb))
{
skip_half = 2;
}
//PSS in subframe 0/5 if FDD
if(frame_parms->frame_type == FDD) //FDD
{
if(((subframe == 0) || (subframe == 5)) &&
(rb > ((frame_parms->N_RB_DL >> 1) - 3)) &&
(rb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == pss_symb))
{
rb_alloc_ind = 0;
}
if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if((frame_parms->frame_type == TDD) &&
(subframe == 6)) //TDD Subframe 6
{
if((rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
if((rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if((rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if(rb_alloc_ind == 1)
{
#ifdef DEBUG_DLSCH_DEMOD
printf("rb %d/symbol %d (skip_half %d)\n", rb, l, skip_half);
#endif
if(pilots == 0)
{
// printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
if(skip_half == 1)
{
memcpy(dl_ch0_ext, dl_ch0, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else if(skip_half == 2)
{
memcpy(dl_ch0_ext, dl_ch0 + 6, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[(i + 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else
{
memcpy(dl_ch0_ext, dl_ch0, 12 * sizeof(int));
for(i = 0; i < 12; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
}
else
{
// printf("Extracting with pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
j = 0;
if(skip_half == 1)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i];
}
}
rxF_ext += 5;
dl_ch0_ext += 5;
}
else if(skip_half == 2)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[(i + 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i + 6];
}
}
dl_ch0_ext += 5;
rxF_ext += 5;
}
else
{
for(i = 0; i < 12; i++)
{
if((i != (frame_parms->nushift + poffset)) &&
(i != ((frame_parms->nushift + poffset + 6) % 12)))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i];
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
}
}
}
dl_ch0 += 12;
rxF += 12;
} // first half loop
// Do middle RB (around DC)
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// PBCH
if((subframe == 0) &&
(l >= (nsymb >> 1)) &&
(l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (l == sss_symb))
{
rb_alloc_ind = 0;
}
if(frame_parms->frame_type == FDD)
{
//PSS
if(((subframe == 0) || (subframe == 5)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
}
//PSS
if((frame_parms->frame_type == TDD) &&
(subframe == 6) &&
(l == pss_symb))
{
rb_alloc_ind = 0;
}
// printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
// printf("DC rb %d (%p)\n",rb,rxF);
if(rb_alloc_ind == 1)
{
#ifdef DEBUG_DLSCH_DEMOD
printf("rb %d/symbol %d (skip_half %d)\n", rb, l, skip_half);
#endif
if(pilots == 0)
{
for(i = 0; i < 6; i++)
{
dl_ch0_ext[i] = dl_ch0[i];
rxF_ext[i] = rxF[i];
}
rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))];
for(; i < 12; i++)
{
dl_ch0_ext[i] = dl_ch0[i];
rxF_ext[i] = rxF[(1 + i - 6)];
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
else // pilots==1
{
j = 0;
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("**extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j - 1], *(1 + (short *)&rxF_ext[j - 1]));
#endif
}
}
rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))];
for(; i < 12; i++)
{
if(i != ((frame_parms->nushift + 6 + poffset) % 12))
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[(1 + i - 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("**extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j - 1], *(1 + (short *)&rxF_ext[j - 1]));
#endif
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
} // symbol_mod==0
} // rballoc==1
else
{
rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))];
}
dl_ch0 += 12;
rxF += 7;
rb++;
for(; rb < frame_parms->N_RB_DL; rb++)
{
// printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
// printf("rb %d (%p)\n",rb,rxF);
skip_half = 0;
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// PBCH
if((subframe == 0) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= nsymb >> 1) && (l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3
if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 1;
}
else if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 2;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == sss_symb))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == sss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == sss_symb))
{
skip_half = 2;
}
if(frame_parms->frame_type == FDD)
{
//PSS
if(((subframe == 0) || (subframe == 5)) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
//PSS
if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if((frame_parms->frame_type == TDD) &&
(subframe == 6)) //TDD Subframe 6
{
if((rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
if((rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if((rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if(rb_alloc_ind == 1)
{
#ifdef DEBUG_DLSCH_DEMOD
printf("rb %d/symbol %d (skip_half %d)\n", rb, l, skip_half);
#endif
/*
printf("rb %d\n",rb);
for (i=0;i<12;i++)
printf("(%d %d)",((short *)dl_ch0)[i<<1],((short*)dl_ch0)[1+(i<<1)]);
printf("\n");
*/
if(pilots == 0)
{
// printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
if(skip_half == 1)
{
memcpy(dl_ch0_ext, dl_ch0, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else if(skip_half == 2)
{
memcpy(dl_ch0_ext, dl_ch0 + 6, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[(i + 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else
{
memcpy(dl_ch0_ext, dl_ch0, 12 * sizeof(int));
for(i = 0; i < 12; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
}
else
{
// printf("Extracting with pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
j = 0;
if(skip_half == 1)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i];
}
}
dl_ch0_ext += 5;
rxF_ext += 5;
}
else if(skip_half == 2)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[(i + 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i + 6];
}
}
dl_ch0_ext += 5;
rxF_ext += 5;
}
else
{
for(i = 0; i < 12; i++)
{
if((i != (frame_parms->nushift + poffset)) &&
(i != ((frame_parms->nushift + poffset + 6) % 12)))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i];
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
}
} // pilots=0
}
dl_ch0 += 12;
rxF += 12;
}
}
}
return(nb_rb / frame_parms->nb_antennas_rx);
}
unsigned short dlsch_extract_rbs_dual(int **rxdataF,
int **dl_ch_estimates,
int **rxdataF_ext,
int **dl_ch_estimates_ext,
unsigned short pmi,
unsigned char *pmi_ext,
unsigned int *rb_alloc,
unsigned char symbol,
unsigned char subframe,
uint32_t high_speed_flag,
LTE_DL_FRAME_PARMS *frame_parms,
MIMO_mode_t mimo_mode)
{
int prb, nb_rb = 0;
int prb_off, prb_off2;
int rb_alloc_ind, skip_half = 0, sss_symb, pss_symb = 0, nsymb, l;
int i, aarx;
int32_t *dl_ch0, *dl_ch0p, *dl_ch0_ext, *dl_ch1, *dl_ch1p, *dl_ch1_ext, *rxF, *rxF_ext;
int symbol_mod, pilots = 0, j = 0;
unsigned char *pmi_loc;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
// printf("extract_rbs: symbol_mod %d\n",symbol_mod);
if((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp)))
{
pilots = 1;
}
nsymb = (frame_parms->Ncp == NORMAL) ? 14 : 12;
l = symbol;
if(frame_parms->frame_type == TDD) // TDD
{
sss_symb = nsymb - 1;
pss_symb = 2;
}
else
{
sss_symb = (nsymb >> 1) - 2;
pss_symb = (nsymb >> 1) - 1;
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
if(high_speed_flag == 1)
{
dl_ch0 = &dl_ch_estimates[aarx][5 + (symbol * (frame_parms->ofdm_symbol_size))];
dl_ch1 = &dl_ch_estimates[2 + aarx][5 + (symbol * (frame_parms->ofdm_symbol_size))];
}
else
{
dl_ch0 = &dl_ch_estimates[aarx][5];
dl_ch1 = &dl_ch_estimates[2 + aarx][5];
}
pmi_loc = pmi_ext;
// pointers to extracted RX signals and channel estimates
rxF_ext = &rxdataF_ext[aarx][symbol * (frame_parms->N_RB_DL * 12)];
dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol * (frame_parms->N_RB_DL * 12)];
dl_ch1_ext = &dl_ch_estimates_ext[2 + aarx][symbol * (frame_parms->N_RB_DL * 12)];
for(prb = 0; prb < frame_parms->N_RB_DL; prb++)
{
skip_half = 0;
if(prb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> prb) & 1;
}
else if(prb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (prb - 32)) & 1;
}
else if(prb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (prb - 64)) & 1;
}
else if(prb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (prb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
if((frame_parms->N_RB_DL & 1) == 0) // even number of RBs
{
// PBCH
if((subframe == 0) &&
(prb >= ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l >= (nsymb >> 1)) &&
(l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
// printf("symbol %d / rb %d: skipping PBCH REs\n",symbol,prb);
}
//SSS
if(((subframe == 0) || (subframe == 5)) &&
(prb >= ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == sss_symb))
{
rb_alloc_ind = 0;
// printf("symbol %d / rb %d: skipping SSS REs\n",symbol,prb);
}
//PSS in subframe 0/5 if FDD
if(frame_parms->frame_type == FDD) //FDD
{
if(((subframe == 0) || (subframe == 5)) &&
(prb >= ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == pss_symb))
{
rb_alloc_ind = 0;
// printf("symbol %d / rb %d: skipping PSS REs\n",symbol,prb);
}
}
if((frame_parms->frame_type == TDD) &&
(subframe == 6)) //TDD Subframe 6
{
if((prb >= ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == pss_symb))
{
rb_alloc_ind = 0;
}
}
if(rb_alloc_ind == 1) // PRB is allocated
{
prb_off = 12 * prb;
prb_off2 = 1 + (12 * (prb - (frame_parms->N_RB_DL >> 1)));
dl_ch0p = dl_ch0 + (12 * prb);
dl_ch1p = dl_ch1 + (12 * prb);
if(prb < (frame_parms->N_RB_DL >> 1))
{
rxF = &rxdataF[aarx][prb_off +
frame_parms->first_carrier_offset +
(symbol * (frame_parms->ofdm_symbol_size))];
}
else
{
rxF = &rxdataF[aarx][prb_off2 +
(symbol * (frame_parms->ofdm_symbol_size))];
}
/*
if (mimo_mode <= PUSCH_PRECODING1)
pmi_loc = (pmi>>((prb>>2)<<1))&3;
else
pmi_loc=(pmi>>prb)&1;*/
*pmi_loc = get_pmi(frame_parms->N_RB_DL, mimo_mode, pmi, prb);
pmi_loc++;
if(pilots == 0)
{
memcpy(dl_ch0_ext, dl_ch0p, 12 * sizeof(int));
memcpy(dl_ch1_ext, dl_ch1p, 12 * sizeof(int));
memcpy(rxF_ext, rxF, 12 * sizeof(int));
dl_ch0_ext += 12;
dl_ch1_ext += 12;
rxF_ext += 12;
}
else // pilots==1
{
j = 0;
for(i = 0; i < 12; i++)
{
if((i != frame_parms->nushift) &&
(i != frame_parms->nushift + 3) &&
(i != frame_parms->nushift + 6) &&
(i != ((frame_parms->nushift + 9) % 12)))
{
rxF_ext[j] = rxF[i];
// printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j]));
dl_ch0_ext[j] = dl_ch0p[i];
dl_ch1_ext[j++] = dl_ch1p[i];
}
}
dl_ch0_ext += 8;
dl_ch1_ext += 8;
rxF_ext += 8;
} // pilots==1
}
}
else // Odd number of RBs
{
// PBCH
if((subframe == 0) &&
(prb > ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l >= (nsymb >> 1)) &&
(l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
// printf("symbol %d / rb %d: skipping PBCH REs\n",symbol,prb);
}
//SSS
if(((subframe == 0) || (subframe == 5)) &&
(prb > ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == sss_symb))
{
rb_alloc_ind = 0;
// printf("symbol %d / rb %d: skipping SSS REs\n",symbol,prb);
}
//PSS in subframe 0/5 if FDD
if(frame_parms->frame_type == FDD) //FDD
{
if(((subframe == 0) || (subframe == 5)) &&
(prb > ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == pss_symb))
{
rb_alloc_ind = 0;
// printf("symbol %d / rb %d: skipping PSS REs\n",symbol,prb);
}
}
if((frame_parms->frame_type == TDD) &&
((subframe == 1) || (subframe == 6))) //TDD Subframe 1-6
{
if((prb > ((frame_parms->N_RB_DL >> 1) - 3)) &&
(prb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == pss_symb))
{
rb_alloc_ind = 0;
}
}
if(rb_alloc_ind == 1)
{
skip_half = 0;
//Check if we have to drop half a PRB due to PSS/SSS/PBCH
// skip_half == 0 means full PRB
// skip_half == 1 means first half is used (leftmost half-PRB from PSS/SSS/PBCH)
// skip_half == 2 means second half is used (rightmost half-PRB from PSS/SSS/PBCH)
//PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3
if((subframe == 0) &&
(prb == ((frame_parms->N_RB_DL >> 1) - 3)) &&
(l >= (nsymb >> 1)) &&
(l < ((nsymb >> 1) + 4)))
{
skip_half = 1;
}
else if((subframe == 0) &&
(prb == ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l >= (nsymb >> 1)) &&
(l < ((nsymb >> 1) + 4)))
{
skip_half = 2;
}
//SSS
if(((subframe == 0) || (subframe == 5)) &&
(prb == ((frame_parms->N_RB_DL >> 1) - 3)) &&
(l == sss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) &&
(prb == ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == sss_symb))
{
skip_half = 2;
}
//PSS Subframe 0,5
if(((frame_parms->frame_type == FDD) &&
(((subframe == 0) || (subframe == 5)))) || //FDD Subframes 0,5
((frame_parms->frame_type == TDD) &&
(((subframe == 1) || (subframe == 6))))) //TDD Subframes 1,6
{
if((prb == ((frame_parms->N_RB_DL >> 1) - 3)) &&
(l == pss_symb))
{
skip_half = 1;
}
else if((prb == ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == pss_symb))
{
skip_half = 2;
}
}
prb_off = 12 * prb;
prb_off2 = 7 + (12 * (prb - (frame_parms->N_RB_DL >> 1) - 1));
dl_ch0p = dl_ch0 + (12 * prb);
dl_ch1p = dl_ch1 + (12 * prb);
if(prb <= (frame_parms->N_RB_DL >> 1))
{
rxF = &rxdataF[aarx][prb_off +
frame_parms->first_carrier_offset +
(symbol * (frame_parms->ofdm_symbol_size))];
}
else
{
rxF = &rxdataF[aarx][prb_off2 +
(symbol * (frame_parms->ofdm_symbol_size))];
}
#ifdef DEBUG_DLSCH_DEMOD
printf("symbol %d / rb %d: alloc %d skip_half %d (rxF %p, rxF_ext %p) prb_off (%d,%d)\n", symbol, prb, rb_alloc_ind, skip_half, rxF, rxF_ext, prb_off, prb_off2);
#endif
/* if (mimo_mode <= PUSCH_PRECODING1)
pmi_loc = (pmi>>((prb>>2)<<1))&3;
else
pmi_loc=(pmi>>prb)&1;
// printf("symbol_mod %d (pilots %d) rb %d, sb %d, pmi %d (pmi_loc %p,rxF %p, ch00 %p, ch01 %p, rxF_ext %p dl_ch0_ext %p dl_ch1_ext %p)\n",symbol_mod,pilots,prb,prb>>2,*pmi_loc,pmi_loc,rxF,dl_ch0, dl_ch1, rxF_ext,dl_ch0_ext,dl_ch1_ext);
*/
*pmi_loc = get_pmi(frame_parms->N_RB_DL, mimo_mode, pmi, prb);
pmi_loc++;
if(prb != (frame_parms->N_RB_DL >> 1)) // This PRB is not around DC
{
if(pilots == 0)
{
if(skip_half == 1)
{
memcpy(dl_ch0_ext, dl_ch0p, 6 * sizeof(int32_t));
memcpy(dl_ch1_ext, dl_ch1p, 6 * sizeof(int32_t));
memcpy(rxF_ext, rxF, 6 * sizeof(int32_t));
#ifdef DEBUG_DLSCH_DEMOD
for(i = 0; i < 6; i++)
{
printf("extract rb %d, re %d => (%d,%d)\n", prb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
}
#endif
dl_ch0_ext += 6;
dl_ch1_ext += 6;
rxF_ext += 6;
}
else if(skip_half == 2)
{
memcpy(dl_ch0_ext, dl_ch0p + 6, 6 * sizeof(int32_t));
memcpy(dl_ch1_ext, dl_ch1p + 6, 6 * sizeof(int32_t));
memcpy(rxF_ext, rxF + 6, 6 * sizeof(int32_t));
#ifdef DEBUG_DLSCH_DEMOD
for(i = 0; i < 6; i++)
{
printf("extract rb %d, re %d => (%d,%d)\n", prb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
}
#endif
dl_ch0_ext += 6;
dl_ch1_ext += 6;
rxF_ext += 6;
}
else // skip_half==0
{
memcpy(dl_ch0_ext, dl_ch0p, 12 * sizeof(int32_t));
memcpy(dl_ch1_ext, dl_ch1p, 12 * sizeof(int32_t));
memcpy(rxF_ext, rxF, 12 * sizeof(int32_t));
#ifdef DEBUG_DLSCH_DEMOD
for(i = 0; i < 12; i++)
{
printf("extract rb %d, re %d => (%d,%d)\n", prb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
}
#endif
dl_ch0_ext += 12;
dl_ch1_ext += 12;
rxF_ext += 12;
}
}
else // pilots=1
{
j = 0;
if(skip_half == 1)
{
for(i = 0; i < 6; i++)
{
if((i != frame_parms->nushift) &&
(i != ((frame_parms->nushift + 3) % 6)))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("(pilots,skip1)extract rb %d, re %d (%d)=> (%d,%d)\n", prb, i, j, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j] = dl_ch0p[i];
dl_ch1_ext[j++] = dl_ch1p[i];
}
}
dl_ch0_ext += 4;
dl_ch1_ext += 4;
rxF_ext += 4;
}
else if(skip_half == 2)
{
for(i = 0; i < 6; i++)
{
if((i != frame_parms->nushift) &&
(i != ((frame_parms->nushift + 3) % 6)))
{
rxF_ext[j] = rxF[(i + 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("(pilots,skip2)extract rb %d, re %d (%d) => (%d,%d)\n", prb, i, j, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j] = dl_ch0p[i + 6];
dl_ch1_ext[j++] = dl_ch1p[i + 6];
}
}
dl_ch0_ext += 4;
dl_ch1_ext += 4;
rxF_ext += 4;
}
else //skip_half==0
{
for(i = 0; i < 12; i++)
{
if((i != frame_parms->nushift) &&
(i != frame_parms->nushift + 3) &&
(i != frame_parms->nushift + 6) &&
(i != ((frame_parms->nushift + 9) % 12)))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("(pilots)extract rb %d, re %d => (%d,%d)\n", prb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j] = dl_ch0p[i];
dl_ch1_ext[j++] = dl_ch1p[i];
}
}
dl_ch0_ext += 8;
dl_ch1_ext += 8;
rxF_ext += 8;
} //skip_half==0
} //pilots==1
}
else // Do middle RB (around DC)
{
if(pilots == 0)
{
memcpy(dl_ch0_ext, dl_ch0p, 6 * sizeof(int32_t));
memcpy(dl_ch1_ext, dl_ch1p, 6 * sizeof(int32_t));
memcpy(rxF_ext, rxF, 6 * sizeof(int32_t));
#ifdef DEBUG_DLSCH_DEMOD
for(i = 0; i < 6; i++)
{
printf("extract rb %d, re %d => (%d,%d)\n", prb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
}
#endif
rxF_ext += 6;
dl_ch0_ext += 6;
dl_ch1_ext += 6;
dl_ch0p += 6;
dl_ch1p += 6;
rxF = &rxdataF[aarx][1 + ((symbol * (frame_parms->ofdm_symbol_size)))];
memcpy(dl_ch0_ext, dl_ch0p, 6 * sizeof(int32_t));
memcpy(dl_ch1_ext, dl_ch1p, 6 * sizeof(int32_t));
memcpy(rxF_ext, rxF, 6 * sizeof(int32_t));
#ifdef DEBUG_DLSCH_DEMOD
for(i = 0; i < 6; i++)
{
printf("extract rb %d, re %d => (%d,%d)\n", prb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
}
#endif
rxF_ext += 6;
dl_ch0_ext += 6;
dl_ch1_ext += 6;
}
else // pilots==1
{
j = 0;
for(i = 0; i < 6; i++)
{
if((i != frame_parms->nushift) &&
(i != ((frame_parms->nushift + 3) % 6)))
{
dl_ch0_ext[j] = dl_ch0p[i];
dl_ch1_ext[j] = dl_ch1p[i];
rxF_ext[j++] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n", prb, i, j, *(short *)&rxF[i], *(1 + (short *)&rxF[i]));
#endif
}
}
rxF = &rxdataF[aarx][1 + symbol * (frame_parms->ofdm_symbol_size)];
for(; i < 12; i++)
{
if((i != ((frame_parms->nushift + 6) % 12)) &&
(i != ((frame_parms->nushift + 9) % 12)))
{
dl_ch0_ext[j] = dl_ch0p[i];
dl_ch1_ext[j] = dl_ch1p[i];
rxF_ext[j++] = rxF[i - 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n", prb, i, j, *(short *)&rxF[1 + i - 6], *(1 + (short *)&rxF[1 + i - 6]));
#endif
}
}
dl_ch0_ext += 8;
dl_ch1_ext += 8;
rxF_ext += 8;
} //pilots==1
} // if Middle PRB
} // if odd PRB
} // if rballoc==1
} // for prb
} // for aarx
return(nb_rb / frame_parms->nb_antennas_rx);
}
unsigned short dlsch_extract_rbs_TM7(int **rxdataF,
int **dl_bf_ch_estimates,
int **rxdataF_ext,
int **dl_bf_ch_estimates_ext,
unsigned int *rb_alloc,
unsigned char symbol,
unsigned char subframe,
uint32_t high_speed_flag,
LTE_DL_FRAME_PARMS *frame_parms)
{
unsigned short rb, nb_rb = 0;
unsigned char rb_alloc_ind;
unsigned char i, aarx, l, nsymb, skip_half = 0, sss_symb, pss_symb = 0;
int *dl_ch0, *dl_ch0_ext, *rxF, *rxF_ext;
unsigned char symbol_mod, pilots = 0, uespec_pilots = 0, j = 0, poffset = 0, uespec_poffset = 0;
int8_t uespec_nushift = frame_parms->Nid_cell % 3;
symbol_mod = (symbol >= (7 - frame_parms->Ncp)) ? symbol - (7 - frame_parms->Ncp) : symbol;
pilots = ((symbol_mod == 0) || (symbol_mod == (4 - frame_parms->Ncp))) ? 1 : 0;
l = symbol;
nsymb = (frame_parms->Ncp == NORMAL) ? 14 : 12;
if(frame_parms->Ncp == 0)
{
if(symbol == 3 || symbol == 6 || symbol == 9 || symbol == 12)
{
uespec_pilots = 1;
}
}
else
{
if(symbol == 4 || symbol == 7 || symbol == 10)
{
uespec_pilots = 1;
}
}
if(frame_parms->frame_type == TDD) // TDD
{
sss_symb = nsymb - 1;
pss_symb = 2;
}
else
{
sss_symb = (nsymb >> 1) - 2;
pss_symb = (nsymb >> 1) - 1;
}
if(symbol_mod == (4 - frame_parms->Ncp))
{
poffset = 3;
}
if((frame_parms->Ncp == 0 && (symbol == 6 || symbol == 12)) || (frame_parms->Ncp == 1 && symbol == 7))
{
uespec_poffset = 2;
}
for(aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
{
if(high_speed_flag == 1)
{
dl_ch0 = &dl_bf_ch_estimates[aarx][symbol * (frame_parms->ofdm_symbol_size)];
}
else
{
dl_ch0 = &dl_bf_ch_estimates[aarx][0];
}
dl_ch0_ext = &dl_bf_ch_estimates_ext[aarx][symbol * (frame_parms->N_RB_DL * 12)];
rxF_ext = &rxdataF_ext[aarx][symbol * (frame_parms->N_RB_DL * 12)];
rxF = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol * (frame_parms->ofdm_symbol_size)))];
if((frame_parms->N_RB_DL & 1) == 0) // even number of RBs
for(rb = 0; rb < frame_parms->N_RB_DL; rb++)
{
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// For second half of RBs skip DC carrier
if(rb == (frame_parms->N_RB_DL >> 1))
{
rxF = &rxdataF[aarx][(1 + (symbol * (frame_parms->ofdm_symbol_size)))];
//dl_ch0++;
}
// PBCH
if((subframe == 0) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= nsymb >> 1) && (l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == sss_symb))
{
rb_alloc_ind = 0;
}
if(frame_parms->frame_type == FDD)
{
//PSS
if(((subframe == 0) || (subframe == 5)) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
}
if((frame_parms->frame_type == TDD) &&
(subframe == 6)) //TDD Subframe 6
{
if((rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
}
if(rb_alloc_ind == 1)
{
/*
printf("rb %d\n",rb);
for (i=0;i<12;i++)
printf("(%d %d)",((short *)dl_ch0)[i<<1],((short*)dl_ch0)[1+(i<<1)]);
printf("\n");
*/
if(pilots == 0 && uespec_pilots == 0)
{
memcpy(dl_ch0_ext, dl_ch0, 12 * sizeof(int));
for(i = 0; i < 12; i++)
{
rxF_ext[i] = rxF[i];
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
else if(pilots == 1 && uespec_pilots == 0)
{
j = 0;
for(i = 0; i < 12; i++)
{
if((i != (frame_parms->nushift + poffset)) &&
(i != ((frame_parms->nushift + poffset + 6) % 12)))
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
}
else if(pilots == 0 && uespec_pilots == 1)
{
j = 0;
for(i = 0; i < 12; i++)
{
if(frame_parms->Ncp == 0)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
}
}
else
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
}
}
}
dl_ch0_ext += 9 - frame_parms->Ncp;
rxF_ext += 9 - frame_parms->Ncp;
}
else
{
LOG_E(PHY, "dlsch_extract_rbs_TM7(dl_demodulation.c):pilot or ue spec pilot detection error\n");
exit(-1);
}
}
dl_ch0 += 12;
rxF += 12;
}
else // Odd number of RBs
{
for(rb = 0; rb < frame_parms->N_RB_DL >> 1; rb++)
{
skip_half = 0;
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// PBCH
if((subframe == 0) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3
if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 1;
}
else if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 2;
}
//SSS
if(((subframe == 0) || (subframe == 5)) &&
(rb > ((frame_parms->N_RB_DL >> 1) - 3)) &&
(rb < ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == sss_symb))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) &&
(rb == ((frame_parms->N_RB_DL >> 1) - 3)) &&
(l == sss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) &&
(rb == ((frame_parms->N_RB_DL >> 1) + 3)) &&
(l == sss_symb))
{
skip_half = 2;
}
//PSS in subframe 0/5 if FDD
if(frame_parms->frame_type == FDD) //FDD
{
if(((subframe == 0) || (subframe == 5)) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if((frame_parms->frame_type == TDD) && ((subframe == 1) || (subframe == 6))) //TDD Subframe 1 and 6
{
if((rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
if((rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if((rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if(rb_alloc_ind == 1)
{
#ifdef DEBUG_DLSCH_DEMOD
printf("rb %d/symbol %d pilots %d, uespec_pilots %d, (skip_half %d)\n", rb, l, pilots, uespec_pilots, skip_half);
#endif
if(pilots == 0 && uespec_pilots == 0)
{
//printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
if(skip_half == 1)
{
memcpy(dl_ch0_ext, dl_ch0, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else if(skip_half == 2)
{
memcpy(dl_ch0_ext, dl_ch0 + 6, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[(i + 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else
{
memcpy(dl_ch0_ext, dl_ch0, 12 * sizeof(int));
for(i = 0; i < 12; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract symbol %d rb %d, re %d => (%d,%d)\n", symbol, rb, i, *(short *)&rxF[i], *(1 + (short *)&rxF[i]));
#endif
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
}
else if(pilots == 1 && uespec_pilots == 0)
{
// printf("Extracting with pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
j = 0;
if(skip_half == 1)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 5;
rxF_ext += 5;
}
else if(skip_half == 2)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[(i + 6)];
dl_ch0_ext[j++] = dl_ch0[i + 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 5;
rxF_ext += 5;
}
else
{
for(i = 0; i < 12; i++)
{
if((i != (frame_parms->nushift + poffset)) &&
(i != ((frame_parms->nushift + poffset + 6) % 12)))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i];
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
}
}
else if(pilots == 0 && uespec_pilots == 1)
{
//printf("Extracting with uespec pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
j = 0;
if(skip_half == 1)
{
if(frame_parms->Ncp == 0)
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 6 - (uespec_nushift + uespec_poffset < 6) - (uespec_nushift + uespec_poffset + 4 < 6) - ((uespec_nushift + uespec_poffset + 8) % 12 < 6);
rxF_ext += 6 - (uespec_nushift + uespec_poffset < 6) - (uespec_nushift + uespec_poffset + 4 < 6) - ((uespec_nushift + uespec_poffset + 8) % 12 < 6);
}
else
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 4;
rxF_ext += 4;
}
}
else if(skip_half == 2)
{
if(frame_parms->Ncp == 0)
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
rxF_ext[j] = rxF[(i + 6)];
dl_ch0_ext[j++] = dl_ch0[i + 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 6 - (uespec_nushift + uespec_poffset > 6) - (uespec_nushift + uespec_poffset + 4 > 6) - ((uespec_nushift + uespec_poffset + 8) % 12 > 6);
rxF_ext += 6 - (uespec_nushift + uespec_poffset > 6) - (uespec_nushift + uespec_poffset + 4 > 6) - ((uespec_nushift + uespec_poffset + 8) % 12 > 6);
}
else
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
rxF_ext[j] = rxF[(i + 6)];
dl_ch0_ext[j++] = dl_ch0[i + 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 4;
rxF_ext += 4;
}
}
else
{
for(i = 0; i < 12; i++)
{
if(frame_parms->Ncp == 0)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract symbol %d, rb %d, re %d, j %d => (%d,%d)\n",
symbol, rb, i, j - 1, *(short *)&dl_ch0[j], *(1 + (short *)&dl_ch0[i]));
#endif
}
}
else
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
}
dl_ch0_ext += 9 - frame_parms->Ncp;
rxF_ext += 9 - frame_parms->Ncp;
}
}
else
{
LOG_E(PHY, "dlsch_extract_rbs_TM7(dl_demodulation.c):pilot or ue spec pilot detection error\n");
exit(-1);
}
}
dl_ch0 += 12;
rxF += 12;
} // first half loop
// Do middle RB (around DC)
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// PBCH
if((subframe == 0) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == sss_symb))
{
rb_alloc_ind = 0;
}
if(frame_parms->frame_type == FDD)
{
//PSS
if(((subframe == 0) || (subframe == 5)) && (rb >= ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
}
if((frame_parms->frame_type == TDD) && ((subframe == 1) || (subframe == 6)))
{
//PSS
if((rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
}
//printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
//printf("DC rb %d (%p)\n",rb,rxF);
if(rb_alloc_ind == 1)
{
//printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half);
if(pilots == 0 && uespec_pilots == 0)
{
for(i = 0; i < 6; i++)
{
dl_ch0_ext[i] = dl_ch0[i];
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))];
for(; i < 12; i++)
{
dl_ch0_ext[i] = dl_ch0[i];
rxF_ext[i] = rxF[(1 + i - 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
else if(pilots == 1 && uespec_pilots == 0) // pilots==1
{
j = 0;
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))];
for(; i < 12; i++)
{
if(i != ((frame_parms->nushift + 6 + poffset) % 12))
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[(1 + i - 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
}
else if(pilots == 0 && uespec_pilots == 1)
{
j = 0;
for(i = 0; i < 6; i++)
{
if(frame_parms->Ncp == 0)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
else
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
}
rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))];
for(; i < 12; i++)
{
if(frame_parms->Ncp == 0)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[(1 + i - 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
else
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
dl_ch0_ext[j] = dl_ch0[i];
rxF_ext[j++] = rxF[(1 + i - 6)];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
}
dl_ch0_ext += 9 - frame_parms->Ncp;
rxF_ext += 9 - frame_parms->Ncp;
}// symbol_mod==0
} // rballoc==1
else
{
rxF = &rxdataF[aarx][((symbol * (frame_parms->ofdm_symbol_size)))];
}
dl_ch0 += 12;
rxF += 7;
rb++;
for(; rb < frame_parms->N_RB_DL; rb++)
{
// printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]);
// printf("rb %d (%p)\n",rb,rxF);
skip_half = 0;
if(rb < 32)
{
rb_alloc_ind = (rb_alloc[0] >> rb) & 1;
}
else if(rb < 64)
{
rb_alloc_ind = (rb_alloc[1] >> (rb - 32)) & 1;
}
else if(rb < 96)
{
rb_alloc_ind = (rb_alloc[2] >> (rb - 64)) & 1;
}
else if(rb < 100)
{
rb_alloc_ind = (rb_alloc[3] >> (rb - 96)) & 1;
}
else
{
rb_alloc_ind = 0;
}
if(rb_alloc_ind == 1)
{
nb_rb++;
}
// PBCH
if((subframe == 0) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= nsymb >> 1) && (l < ((nsymb >> 1) + 4)))
{
rb_alloc_ind = 0;
}
//PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3
if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 1;
}
else if((subframe == 0) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l >= (nsymb >> 1)) && (l < ((nsymb >> 1) + 4)))
{
skip_half = 2;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == sss_symb))
{
rb_alloc_ind = 0;
}
//SSS
if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == sss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == sss_symb))
{
skip_half = 2;
}
//PSS
if(frame_parms->frame_type == FDD)
{
if(((subframe == 0) || (subframe == 5)) && (rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if(((subframe == 0) || (subframe == 5)) && (rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if((frame_parms->frame_type == TDD) && ((subframe == 1) || (subframe == 6))) //TDD Subframe 1 and 6
{
if((rb > ((frame_parms->N_RB_DL >> 1) - 3)) && (rb < ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
rb_alloc_ind = 0;
}
if((rb == ((frame_parms->N_RB_DL >> 1) - 3)) && (l == pss_symb))
{
skip_half = 1;
}
else if((rb == ((frame_parms->N_RB_DL >> 1) + 3)) && (l == pss_symb))
{
skip_half = 2;
}
}
if(rb_alloc_ind == 1)
{
#ifdef DEBUG_DLSCH_DEMOD
printf("rb %d/symbol %d (skip_half %d)\n", rb, l, skip_half);
#endif
/*
printf("rb %d\n",rb);
for (i=0;i<12;i++)
printf("(%d %d)",((short *)dl_ch0)[i<<1],((short*)dl_ch0)[1+(i<<1)]);
printf("\n");
*/
if(pilots == 0 && uespec_pilots == 0)
{
//printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
if(skip_half == 1)
{
memcpy(dl_ch0_ext, dl_ch0, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else if(skip_half == 2)
{
memcpy(dl_ch0_ext, dl_ch0 + 6, 6 * sizeof(int));
for(i = 0; i < 6; i++)
{
rxF_ext[i] = rxF[i + 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 6;
rxF_ext += 6;
}
else
{
memcpy(dl_ch0_ext, dl_ch0, 12 * sizeof(int));
//printf("symbol %d, extract rb %d, => (%d,%d)\n",symbol,rb,*(short *)&dl_ch0[j],*(1+(short*)&dl_ch0[i]));
for(i = 0; i < 12; i++)
{
rxF_ext[i] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
dl_ch0_ext += 12;
rxF_ext += 12;
}
}
else if(pilots == 1 && uespec_pilots == 0)
{
//printf("Extracting with pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half);
j = 0;
if(skip_half == 1)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 5;
rxF_ext += 5;
}
else if(skip_half == 2)
{
for(i = 0; i < 6; i++)
{
if(i != ((frame_parms->nushift + poffset) % 6))
{
rxF_ext[j] = rxF[(i + 6)];
dl_ch0_ext[j++] = dl_ch0[i + 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 5;
rxF_ext += 5;
}
else
{
for(i = 0; i < 12; i++)
{
if((i != (frame_parms->nushift + poffset)) &&
(i != ((frame_parms->nushift + poffset + 6) % 12)))
{
rxF_ext[j] = rxF[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[j], *(1 + (short *)&rxF_ext[j]));
#endif
dl_ch0_ext[j++] = dl_ch0[i];
}
}
dl_ch0_ext += 10;
rxF_ext += 10;
}
}
else if(pilots == 0 && uespec_pilots == 1)
{
j = 0;
if(skip_half == 1)
{
if(frame_parms->Ncp == 0)
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 6 - (uespec_nushift + uespec_poffset < 6) - (uespec_nushift + uespec_poffset + 4 < 6) - ((uespec_nushift + uespec_poffset + 8) % 12 < 6);
rxF_ext += 6 - (uespec_nushift + uespec_poffset < 6) - (uespec_nushift + uespec_poffset + 4 < 6) - ((uespec_nushift + uespec_poffset + 8) % 12 < 6);
}
else
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 4;
rxF_ext += 4;
}
}
else if(skip_half == 2)
{
if(frame_parms->Ncp == 0)
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
rxF_ext[j] = rxF[i + 6];
dl_ch0_ext[j++] = dl_ch0[i + 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 6 - (uespec_nushift + uespec_poffset > 6) - (uespec_nushift + uespec_poffset + 4 > 6) - ((uespec_nushift + uespec_poffset + 8) % 12 > 6);
rxF_ext += 6 - (uespec_nushift + uespec_poffset > 6) - (uespec_nushift + uespec_poffset + 4 > 6) - ((uespec_nushift + uespec_poffset + 8) % 12 > 6);
}
else
{
for(i = 0; i < 6; i++)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
rxF_ext[j] = rxF[(i + 6)];
dl_ch0_ext[j++] = dl_ch0[i + 6];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
dl_ch0_ext += 4;
rxF_ext += 4;
}
}
else
{
for(i = 0; i < 12; i++)
{
if(frame_parms->Ncp == 0)
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 4 && i != (uespec_nushift + uespec_poffset + 8) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
else
{
if(i != uespec_nushift + uespec_poffset && i != uespec_nushift + uespec_poffset + 3 && i != uespec_nushift + uespec_poffset + 6 && i != (uespec_nushift + uespec_poffset + 9) % 12)
{
rxF_ext[j] = rxF[i];
dl_ch0_ext[j++] = dl_ch0[i];
#ifdef DEBUG_DLSCH_DEMOD
printf("extract rb %d, re %d => (%d,%d)\n", rb, i, *(short *)&rxF_ext[i], *(1 + (short *)&rxF_ext[i]));
#endif
}
}
}
dl_ch0_ext += 9 - frame_parms->Ncp;
rxF_ext += 9 - frame_parms->Ncp;
}
}// pilots=0
}
dl_ch0 += 12;
rxF += 12;
}
}
}
_mm_empty();
_m_empty();
return(nb_rb / frame_parms->nb_antennas_rx);
}
//==============================================================================================
void dump_dlsch2(PHY_VARS_UE *ue, uint8_t eNB_id, uint8_t subframe, unsigned int *coded_bits_per_codeword, int round, unsigned char harq_pid)
{
#define NSYMB ((ue->frame_parms.Ncp == 0) ? 14 : 12)
char fname[32], vname[32];
sprintf(fname, "dlsch%d_rxF_r%d_ext0.m", eNB_id, round);
sprintf(vname, "dl%d_rxF_r%d_ext0", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_ext[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
if(ue->frame_parms.nb_antennas_rx > 1)
{
sprintf(fname, "dlsch%d_rxF_r%d_ext1.m", eNB_id, round);
sprintf(vname, "dl%d_rxF_r%d_ext1", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_ext[1],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
}
sprintf(fname, "dlsch%d_ch_r%d_ext00.m", eNB_id, round);
sprintf(vname, "dl%d_ch_r%d_ext00", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
if(ue->transmission_mode[eNB_id] == 7)
{
sprintf(fname, "dlsch%d_bf_ch_r%d.m", eNB_id, round);
sprintf(vname, "dl%d_bf_ch_r%d", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_bf_ch_estimates[0], 512 * NSYMB, 1, 1);
//LOG_M(fname,vname,phy_vars_ue->lte_ue_pdsch_vars[eNB_id]->dl_bf_ch_estimates[0],512,1,1);
sprintf(fname, "dlsch%d_bf_ch_r%d_ext00.m", eNB_id, round);
sprintf(vname, "dl%d_bf_ch_r%d_ext00", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_bf_ch_estimates_ext[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
}
if(ue->frame_parms.nb_antennas_rx == 2)
{
sprintf(fname, "dlsch%d_ch_r%d_ext01.m", eNB_id, round);
sprintf(vname, "dl%d_ch_r%d_ext01", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[1],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
}
if(ue->frame_parms.nb_antenna_ports_eNB == 2)
{
sprintf(fname, "dlsch%d_ch_r%d_ext10.m", eNB_id, round);
sprintf(vname, "dl%d_ch_r%d_ext10", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[2],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
if(ue->frame_parms.nb_antennas_rx == 2)
{
sprintf(fname, "dlsch%d_ch_r%d_ext11.m", eNB_id, round);
sprintf(vname, "dl%d_ch_r%d_ext11", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[3],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
}
}
sprintf(fname, "dlsch%d_rxF_r%d_uespec0.m", eNB_id, round);
sprintf(vname, "dl%d_rxF_r%d_uespec0", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_uespec_pilots[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
/*
LOG_M("dlsch%d_ch_ext01.m","dl01_ch0_ext",pdsch_vars[eNB_id]->dl_ch_estimates_ext[1],12*N_RB_DL*NSYMB,1,1);
LOG_M("dlsch%d_ch_ext10.m","dl10_ch0_ext",pdsch_vars[eNB_id]->dl_ch_estimates_ext[2],12*N_RB_DL*NSYMB,1,1);
LOG_M("dlsch%d_ch_ext11.m","dl11_ch0_ext",pdsch_vars[eNB_id]->dl_ch_estimates_ext[3],12*N_RB_DL*NSYMB,1,1);
*/
sprintf(fname, "dlsch%d_r%d_rho.m", eNB_id, round);
sprintf(vname, "dl_rho_r%d_%d", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_rho_ext[harq_pid][round][0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
sprintf(fname, "dlsch%d_r%d_rho2.m", eNB_id, round);
sprintf(vname, "dl_rho2_r%d_%d", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_rho2_ext[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
sprintf(fname, "dlsch%d_rxF_r%d_comp0.m", eNB_id, round);
sprintf(vname, "dl%d_rxF_r%d_comp0", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_comp0[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
if(ue->frame_parms.nb_antenna_ports_eNB == 2)
{
sprintf(fname, "dlsch%d_rxF_r%d_comp1.m", eNB_id, round);
sprintf(vname, "dl%d_rxF_r%d_comp1", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_comp1[harq_pid][round][0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
}
sprintf(fname, "dlsch%d_rxF_r%d_llr.m", eNB_id, round);
sprintf(vname, "dl%d_r%d_llr", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->llr[0], coded_bits_per_codeword[0], 1, 0);
sprintf(fname, "dlsch%d_r%d_mag1.m", eNB_id, round);
sprintf(vname, "dl%d_r%d_mag1", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_mag0[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
sprintf(fname, "dlsch%d_r%d_mag2.m", eNB_id, round);
sprintf(vname, "dl%d_r%d_mag2", eNB_id, round);
LOG_M(fname, vname, ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_magb0[0],
12 * (ue->frame_parms.N_RB_DL)*NSYMB, 1, 1);
}
| {
"alphanum_fraction": 0.4579483406,
"avg_line_length": 45.6117278307,
"ext": "c",
"hexsha": "6653662b7529598bac52e0d7758096a01f6f7512",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "93e5617d68431a477e803af2fa66290fd52470d2",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "AManTw/oai5g",
"max_forks_repo_path": "openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "93e5617d68431a477e803af2fa66290fd52470d2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "AManTw/oai5g",
"max_issues_repo_path": "openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c",
"max_line_length": 368,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "93e5617d68431a477e803af2fa66290fd52470d2",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "AManTw/oai5g",
"max_stars_repo_path": "openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 101478,
"size": 349249
} |
/* eigen/gen.c
*
* Copyright (C) 2006, 2007 Patrick Alken
*
* 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 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
* 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.
*/
#include <stdlib.h>
#include <math.h>
#include <config.h>
#include <gsl/gsl_eigen.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_blas.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_vector_complex.h>
#include <gsl/gsl_matrix.h>
/*
* This module computes the eigenvalues of a real generalized
* eigensystem A x = \lambda B x. Left and right Schur vectors
* are optionally computed as well.
*
* Based on the algorithm from Moler and Stewart
* [1] C. Moler, G. Stewart, "An Algorithm for Generalized Matrix
* Eigenvalue Problems", SIAM J. Numer. Anal., Vol 10, No 2, 1973.
*
* This algorithm is also described in the book
* [2] Golub & Van Loan, "Matrix Computations" (3rd ed), algorithm 7.7.3
*
* This file contains routines based on original code from LAPACK
* which is distributed under the modified BSD license.
*/
#define GEN_ESHIFT_COEFF (1.736)
static void gen_schur_decomp(gsl_matrix *H, gsl_matrix *R,
gsl_vector_complex *alpha, gsl_vector *beta,
gsl_eigen_gen_workspace *w);
static inline int gen_qzstep(gsl_matrix *H, gsl_matrix *R,
gsl_eigen_gen_workspace *w);
static inline void gen_qzstep_d(gsl_matrix *H, gsl_matrix *R,
gsl_eigen_gen_workspace *w);
static void gen_tri_split_top(gsl_matrix *H, gsl_matrix *R,
gsl_eigen_gen_workspace *w);
static inline void gen_tri_chase_zero(gsl_matrix *H, gsl_matrix *R,
size_t q,
gsl_eigen_gen_workspace *w);
static inline void gen_tri_zero_H(gsl_matrix *H, gsl_matrix *R,
gsl_eigen_gen_workspace *w);
static inline size_t gen_search_small_elements(gsl_matrix *H,
gsl_matrix *R,
int *flag,
gsl_eigen_gen_workspace *w);
static int gen_schur_standardize1(gsl_matrix *A, gsl_matrix *B,
double *alphar, double *beta,
gsl_eigen_gen_workspace *w);
static int gen_schur_standardize2(gsl_matrix *A, gsl_matrix *B,
gsl_complex *alpha1,
gsl_complex *alpha2,
double *beta1, double *beta2,
gsl_eigen_gen_workspace *w);
static int gen_compute_eigenvals(gsl_matrix *A, gsl_matrix *B,
gsl_complex *alpha1,
gsl_complex *alpha2, double *beta1,
double *beta2);
static void gen_store_eigval1(const gsl_matrix *H, const double a,
const double b, gsl_vector_complex *alpha,
gsl_vector *beta,
gsl_eigen_gen_workspace *w);
static void gen_store_eigval2(const gsl_matrix *H,
const gsl_complex *alpha1,
const double beta1,
const gsl_complex *alpha2,
const double beta2,
gsl_vector_complex *alpha,
gsl_vector *beta,
gsl_eigen_gen_workspace *w);
static inline size_t gen_get_submatrix(const gsl_matrix *A,
const gsl_matrix *B);
/*FIX**/
inline static double normF (gsl_matrix * A);
inline static void create_givens (const double a, const double b, double *c, double *s);
/*
gsl_eigen_gen_alloc()
Allocate a workspace for solving the generalized eigenvalue problem.
The size of this workspace is O(n)
Inputs: n - size of matrices
Return: pointer to workspace
*/
gsl_eigen_gen_workspace *
gsl_eigen_gen_alloc(const size_t n)
{
gsl_eigen_gen_workspace *w;
if (n == 0)
{
GSL_ERROR_NULL ("matrix dimension must be positive integer",
GSL_EINVAL);
}
w = (gsl_eigen_gen_workspace *) calloc (1, sizeof (gsl_eigen_gen_workspace));
if (w == 0)
{
GSL_ERROR_NULL ("failed to allocate space for workspace", GSL_ENOMEM);
}
w->size = n;
w->max_iterations = 30 * n;
w->n_evals = 0;
w->n_iter = 0;
w->needtop = 0;
w->atol = 0.0;
w->btol = 0.0;
w->ascale = 0.0;
w->bscale = 0.0;
w->eshift = 0.0;
w->H = NULL;
w->R = NULL;
w->compute_s = 0;
w->compute_t = 0;
w->Q = NULL;
w->Z = NULL;
w->work = gsl_vector_alloc(n);
if (w->work == 0)
{
gsl_eigen_gen_free(w);
GSL_ERROR_NULL ("failed to allocate space for additional workspace", GSL_ENOMEM);
}
return (w);
} /* gsl_eigen_gen_alloc() */
/*
gsl_eigen_gen_free()
Free workspace w
*/
void
gsl_eigen_gen_free (gsl_eigen_gen_workspace * w)
{
RETURN_IF_NULL (w);
if (w->work)
gsl_vector_free(w->work);
free(w);
} /* gsl_eigen_gen_free() */
/*
gsl_eigen_gen_params()
Set parameters which define how we solve the eigenvalue problem
Inputs: compute_s - 1 if we want to compute S, 0 if not
compute_t - 1 if we want to compute T, 0 if not
balance - 1 if we want to balance matrices, 0 if not
w - gen workspace
Return: none
*/
void
gsl_eigen_gen_params (const int compute_s, const int compute_t,
const int balance, gsl_eigen_gen_workspace *w)
{
w->compute_s = compute_s;
w->compute_t = compute_t;
} /* gsl_eigen_gen_params() */
/*
gsl_eigen_gen()
Solve the generalized eigenvalue problem
A x = \lambda B x
for the eigenvalues \lambda.
Inputs: A - general real matrix
B - general real matrix
alpha - where to store eigenvalue numerators
beta - where to store eigenvalue denominators
w - workspace
Return: success or error
*/
int
gsl_eigen_gen (gsl_matrix * A, gsl_matrix * B, gsl_vector_complex * alpha,
gsl_vector * beta, gsl_eigen_gen_workspace * w)
{
const size_t N = A->size1;
/* check matrix and vector sizes */
if (N != A->size2)
{
GSL_ERROR ("matrix must be square to compute eigenvalues", GSL_ENOTSQR);
}
else if ((N != B->size1) || (N != B->size2))
{
GSL_ERROR ("B matrix dimensions must match A", GSL_EBADLEN);
}
else if (alpha->size != N || beta->size != N)
{
GSL_ERROR ("eigenvalue vector must match matrix size", GSL_EBADLEN);
}
else if (w->size != N)
{
GSL_ERROR ("matrix size does not match workspace", GSL_EBADLEN);
}
else
{
double anorm, bnorm;
/* compute the Hessenberg-Triangular reduction of (A, B) */
gsl_linalg_hesstri_decomp(A, B, w->Q, w->Z, w->work);
/* save pointers to original matrices */
w->H = A;
w->R = B;
w->n_evals = 0;
w->n_iter = 0;
w->eshift = 0.0;
/* determine if we need to compute top indices in QZ step */
w->needtop = w->Q != 0 || w->Z != 0 || w->compute_t || w->compute_s;
/* compute matrix norms */
anorm = normF(A);
bnorm = normF(B);
/* compute tolerances and scaling factors */
w->atol = GSL_MAX(GSL_DBL_MIN, GSL_DBL_EPSILON * anorm);
w->btol = GSL_MAX(GSL_DBL_MIN, GSL_DBL_EPSILON * bnorm);
w->ascale = 1.0 / GSL_MAX(GSL_DBL_MIN, anorm);
w->bscale = 1.0 / GSL_MAX(GSL_DBL_MIN, bnorm);
/* compute the generalized Schur decomposition and eigenvalues */
gen_schur_decomp(A, B, alpha, beta, w);
if (w->n_evals != N)
return GSL_EMAXITER;
return GSL_SUCCESS;
}
} /* gsl_eigen_gen() */
/*
gsl_eigen_gen_QZ()
Solve the generalized eigenvalue problem
A x = \lambda B x
for the eigenvalues \lambda. Optionally compute left and/or right
Schur vectors Q and Z which satisfy:
A = Q S Z^t
B = Q T Z^t
where (S, T) is the generalized Schur form of (A, B)
Inputs: A - general real matrix
B - general real matrix
alpha - where to store eigenvalue numerators
beta - where to store eigenvalue denominators
Q - if non-null, where to store left Schur vectors
Z - if non-null, where to store right Schur vectors
w - workspace
Return: success or error
*/
int
gsl_eigen_gen_QZ (gsl_matrix * A, gsl_matrix * B,
gsl_vector_complex * alpha, gsl_vector * beta,
gsl_matrix * Q, gsl_matrix * Z,
gsl_eigen_gen_workspace * w)
{
if (Q && (A->size1 != Q->size1 || A->size1 != Q->size2))
{
GSL_ERROR("Q matrix has wrong dimensions", GSL_EBADLEN);
}
else if (Z && (A->size1 != Z->size1 || A->size1 != Z->size2))
{
GSL_ERROR("Z matrix has wrong dimensions", GSL_EBADLEN);
}
else
{
int s;
w->Q = Q;
w->Z = Z;
s = gsl_eigen_gen(A, B, alpha, beta, w);
w->Q = NULL;
w->Z = NULL;
return s;
}
} /* gsl_eigen_gen_QZ() */
/********************************************
* INTERNAL ROUTINES *
********************************************/
/*
gen_schur_decomp()
Compute the generalized Schur decomposition of the matrix pencil
(H, R) which is in Hessenberg-Triangular form
Inputs: H - upper hessenberg matrix
R - upper triangular matrix
alpha - (output) where to store eigenvalue numerators
beta - (output) where to store eigenvalue denominators
w - workspace
Return: none
Notes: 1) w->n_evals is updated to keep track of how many eigenvalues
are found
*/
static void
gen_schur_decomp(gsl_matrix *H, gsl_matrix *R, gsl_vector_complex *alpha,
gsl_vector *beta, gsl_eigen_gen_workspace *w)
{
size_t N;
gsl_matrix_view h, r;
gsl_matrix_view vh, vr;
size_t q; /* index of small subdiagonal element */
gsl_complex z1, z2; /* complex values */
double a, b;
int s;
int flag;
N = H->size1;
h = gsl_matrix_submatrix(H, 0, 0, N, N);
r = gsl_matrix_submatrix(R, 0, 0, N, N);
while ((N > 1) && (w->n_iter)++ < w->max_iterations)
{
q = gen_search_small_elements(&h.matrix, &r.matrix, &flag, w);
if (flag == 0)
{
/* no small elements found - do a QZ sweep */
s = gen_qzstep(&h.matrix, &r.matrix, w);
if (s == GSL_CONTINUE)
{
/*
* (h, r) is a 2-by-2 block with complex eigenvalues -
* standardize and read off eigenvalues
*/
s = gen_schur_standardize2(&h.matrix,
&r.matrix,
&z1,
&z2,
&a,
&b,
w);
if (s != GSL_SUCCESS)
{
/*
* if we get here, then the standardization process
* perturbed the eigenvalues onto the real line -
* continue QZ iteration to break them into 1-by-1
* blocks
*/
continue;
}
gen_store_eigval2(&h.matrix, &z1, a, &z2, b, alpha, beta, w);
N = 0;
} /* if (s) */
continue;
} /* if (flag == 0) */
else if (flag == 2)
{
if (q == 0)
{
/*
* the leading element of R is zero, split off a block
* at the top
*/
gen_tri_split_top(&h.matrix, &r.matrix, w);
}
else
{
/*
* we found a small element on the diagonal of R - chase the
* zero to the bottom of the active block and then zero
* H(n, n - 1) to split off a 1-by-1 block
*/
if (q != N - 1)
gen_tri_chase_zero(&h.matrix, &r.matrix, q, w);
/* now zero H(n, n - 1) */
gen_tri_zero_H(&h.matrix, &r.matrix, w);
}
/* continue so the next iteration detects the zero in H */
continue;
}
/*
* a small subdiagonal element of H was found - one or two
* eigenvalues have converged or the matrix has split into
* two smaller matrices
*/
if (q == (N - 1))
{
/*
* the last subdiagonal element of the hessenberg matrix is 0 -
* H_{NN} / R_{NN} is a real eigenvalue - standardize so
* R_{NN} > 0
*/
vh = gsl_matrix_submatrix(&h.matrix, q, q, 1, 1);
vr = gsl_matrix_submatrix(&r.matrix, q, q, 1, 1);
gen_schur_standardize1(&vh.matrix, &vr.matrix, &a, &b, w);
gen_store_eigval1(&vh.matrix, a, b, alpha, beta, w);
--N;
h = gsl_matrix_submatrix(&h.matrix, 0, 0, N, N);
r = gsl_matrix_submatrix(&r.matrix, 0, 0, N, N);
}
else if (q == (N - 2))
{
/* bottom right 2-by-2 block may have converged */
vh = gsl_matrix_submatrix(&h.matrix, q, q, 2, 2);
vr = gsl_matrix_submatrix(&r.matrix, q, q, 2, 2);
s = gen_schur_standardize2(&vh.matrix,
&vr.matrix,
&z1,
&z2,
&a,
&b,
w);
if (s != GSL_SUCCESS)
{
/*
* this 2-by-2 block contains real eigenvalues that
* have not yet separated into 1-by-1 blocks -
* recursively call gen_schur_decomp() to finish off
* this block
*/
gen_schur_decomp(&vh.matrix, &vr.matrix, alpha, beta, w);
}
else
{
/* we got 2 complex eigenvalues */
gen_store_eigval2(&vh.matrix, &z1, a, &z2, b, alpha, beta, w);
}
N -= 2;
h = gsl_matrix_submatrix(&h.matrix, 0, 0, N, N);
r = gsl_matrix_submatrix(&r.matrix, 0, 0, N, N);
}
else if (q == 1)
{
/* H_{11} / R_{11} is an eigenvalue */
vh = gsl_matrix_submatrix(&h.matrix, 0, 0, 1, 1);
vr = gsl_matrix_submatrix(&r.matrix, 0, 0, 1, 1);
gen_schur_standardize1(&vh.matrix, &vr.matrix, &a, &b, w);
gen_store_eigval1(&vh.matrix, a, b, alpha, beta, w);
--N;
h = gsl_matrix_submatrix(&h.matrix, 1, 1, N, N);
r = gsl_matrix_submatrix(&r.matrix, 1, 1, N, N);
}
else if (q == 2)
{
/* upper left 2-by-2 block may have converged */
vh = gsl_matrix_submatrix(&h.matrix, 0, 0, 2, 2);
vr = gsl_matrix_submatrix(&r.matrix, 0, 0, 2, 2);
s = gen_schur_standardize2(&vh.matrix,
&vr.matrix,
&z1,
&z2,
&a,
&b,
w);
if (s != GSL_SUCCESS)
{
/*
* this 2-by-2 block contains real eigenvalues that
* have not yet separated into 1-by-1 blocks -
* recursively call gen_schur_decomp() to finish off
* this block
*/
gen_schur_decomp(&vh.matrix, &vr.matrix, alpha, beta, w);
}
else
{
/* we got 2 complex eigenvalues */
gen_store_eigval2(&vh.matrix, &z1, a, &z2, b, alpha, beta, w);
}
N -= 2;
h = gsl_matrix_submatrix(&h.matrix, 2, 2, N, N);
r = gsl_matrix_submatrix(&r.matrix, 2, 2, N, N);
}
else
{
/*
* There is a zero element on the subdiagonal somewhere
* in the middle of the matrix - we can now operate
* separately on the two submatrices split by this
* element. q is the row index of the zero element.
*/
/* operate on lower right (N - q)-by-(N - q) block first */
vh = gsl_matrix_submatrix(&h.matrix, q, q, N - q, N - q);
vr = gsl_matrix_submatrix(&r.matrix, q, q, N - q, N - q);
gen_schur_decomp(&vh.matrix, &vr.matrix, alpha, beta, w);
/* operate on upper left q-by-q block */
vh = gsl_matrix_submatrix(&h.matrix, 0, 0, q, q);
vr = gsl_matrix_submatrix(&r.matrix, 0, 0, q, q);
gen_schur_decomp(&vh.matrix, &vr.matrix, alpha, beta, w);
N = 0;
}
} /* while ((N > 1) && (w->n_iter)++ < w->max_iterations) */
/* handle special case of N = 1 */
if (N == 1)
{
gen_schur_standardize1(&h.matrix, &r.matrix, &a, &b, w);
gen_store_eigval1(&h.matrix, a, b, alpha, beta, w);
}
} /* gen_schur_decomp() */
/*
gen_qzstep()
This routine determines what type of QZ step to perform on
the generalized matrix pair (H, R). If the pair is 3-by-3 or bigger,
we look at the bottom right 2-by-2 block. If this block has complex
eigenvalues, we perform a Francis double shift QZ sweep. If it
has real eigenvalues, we perform an implicit single shift QZ sweep.
If the pair is 2-by-2 with real eigenvalues, we perform a single
shift sweep. If it has complex eigenvalues, we return GSL_CONTINUE
to notify the calling function that a 2-by-2 block with complex
eigenvalues has converged, so that it may then call
gen_schur_standardize2(). In the real eigenvalue case, we want to
continue doing QZ sweeps to break it up into two 1-by-1 blocks.
See LAPACK routine DHGEQZ and [1] for more information.
Inputs: H - upper Hessenberg matrix (at least 2-by-2)
R - upper triangular matrix (at least 2-by-2)
w - workspace
Return: GSL_SUCCESS on normal completion
GSL_CONTINUE if we detect a 2-by-2 block with complex eigenvalues
*/
static inline int
gen_qzstep(gsl_matrix *H, gsl_matrix *R, gsl_eigen_gen_workspace *w)
{
const size_t N = H->size1;
gsl_matrix_view vh, vr; /* views of bottom right 2-by-2 block */
double wr1, wr2, wi;
double scale1, scale2, scale;
double cs, sn; /* givens rotation */
double temp, /* temporary variables */
temp2;
size_t j; /* looping */
gsl_vector_view xv, yv; /* temporary views */
size_t top;
size_t rows;
if (w->n_iter % 10 == 0)
{
/*
* Exceptional shift - we have gone 10 iterations without finding
* a new eigenvalue, do a single shift sweep with an
* exceptional shift
*/
if ((GSL_DBL_MIN * w->max_iterations) *
fabs(gsl_matrix_get(H, N - 2, N - 1)) <
fabs(gsl_matrix_get(R, N - 2, N - 2)))
{
w->eshift += gsl_matrix_get(H, N - 2, N - 1) /
gsl_matrix_get(R, N - 2, N - 2);
}
else
w->eshift += 1.0 / (GSL_DBL_MIN * w->max_iterations);
if ((w->eshift < GSL_DBL_EPSILON) &&
(GSL_DBL_MIN * w->max_iterations) *
fabs(gsl_matrix_get(H, N - 1, N - 2)) <
fabs(gsl_matrix_get(R, N - 2, N - 2)))
{
w->eshift = GEN_ESHIFT_COEFF *
(w->ascale * gsl_matrix_get(H, N - 1, N - 2)) /
(w->bscale * gsl_matrix_get(R, N - 2, N - 2));
}
scale1 = 1.0;
wr1 = w->eshift;
}
else
{
/*
* Compute generalized eigenvalues of bottom right 2-by-2 block
* to be used as shifts - wr1 is the Wilkinson shift
*/
vh = gsl_matrix_submatrix(H, N - 2, N - 2, 2, 2);
vr = gsl_matrix_submatrix(R, N - 2, N - 2, 2, 2);
gsl_schur_gen_eigvals(&vh.matrix,
&vr.matrix,
&wr1,
&wr2,
&wi,
&scale1,
&scale2);
if (wi != 0.0)
{
/* complex eigenvalues */
if (N == 2)
{
/*
* its a 2-by-2 block with complex eigenvalues - notify
* the calling function to deflate
*/
return (GSL_CONTINUE);
}
else
{
/* do a francis double shift sweep */
gen_qzstep_d(H, R, w);
}
return GSL_SUCCESS;
}
}
/* real eigenvalues - perform single shift QZ step */
temp = GSL_MIN(w->ascale, 1.0) * (0.5 / GSL_DBL_MIN);
if (scale1 > temp)
scale = temp / scale1;
else
scale = 1.0;
temp = GSL_MIN(w->bscale, 1.0) * (0.5 / GSL_DBL_MIN);
if (fabs(wr1) > temp)
scale = GSL_MIN(scale, temp / fabs(wr1));
scale1 *= scale;
wr1 *= scale;
if (w->needtop)
{
/* get absolute index of this matrix relative to original matrix */
top = gen_get_submatrix(w->H, H);
}
temp = scale1*gsl_matrix_get(H, 0, 0) - wr1*gsl_matrix_get(R, 0, 0);
temp2 = scale1*gsl_matrix_get(H, 1, 0);
create_givens(temp, temp2, &cs, &sn);
sn = -sn;
for (j = 0; j < N - 1; ++j)
{
if (j > 0)
{
temp = gsl_matrix_get(H, j, j - 1);
temp2 = gsl_matrix_get(H, j + 1, j - 1);
create_givens(temp, temp2, &cs, &sn);
sn = -sn;
/* apply to column (j - 1) */
temp = cs * gsl_matrix_get(H, j, j - 1) +
sn * gsl_matrix_get(H, j + 1, j - 1);
gsl_matrix_set(H, j, j - 1, temp);
gsl_matrix_set(H, j + 1, j - 1, 0.0);
}
/* apply G to H(j:j+1,:) and T(j:j+1,:) */
if (w->compute_s)
{
xv = gsl_matrix_subrow(w->H, top + j, top + j, w->size - top - j);
yv = gsl_matrix_subrow(w->H, top + j + 1, top + j, w->size - top - j);
}
else
{
xv = gsl_matrix_subrow(H, j, j, N - j);
yv = gsl_matrix_subrow(H, j + 1, j, N - j);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
if (w->compute_t)
{
xv = gsl_matrix_subrow(w->R, top + j, top + j, w->size - top - j);
yv = gsl_matrix_subrow(w->R, top + j + 1, top + j, w->size - top - j);
}
else
{
xv = gsl_matrix_subrow(R, j, j, N - j);
yv = gsl_matrix_subrow(R, j + 1, j, N - j);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
if (w->Q)
{
/* accumulate Q: Q -> QG */
xv = gsl_matrix_column(w->Q, top + j);
yv = gsl_matrix_column(w->Q, top + j + 1);
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
}
temp = gsl_matrix_get(R, j + 1, j + 1);
temp2 = gsl_matrix_get(R, j + 1, j);
create_givens(temp, temp2, &cs, &sn);
rows = GSL_MIN(j + 3, N);
if (w->compute_s)
{
xv = gsl_matrix_subcolumn(w->H, top + j, 0, top + rows);
yv = gsl_matrix_subcolumn(w->H, top + j + 1, 0, top + rows);
}
else
{
xv = gsl_matrix_subcolumn(H, j, 0, rows);
yv = gsl_matrix_subcolumn(H, j + 1, 0, rows);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
rows = GSL_MIN(j + 2, N);
if (w->compute_t)
{
xv = gsl_matrix_subcolumn(w->R, top + j, 0, top + rows);
yv = gsl_matrix_subcolumn(w->R, top + j + 1, 0, top + rows);
}
else
{
xv = gsl_matrix_subcolumn(R, j, 0, rows);
yv = gsl_matrix_subcolumn(R, j + 1, 0, rows);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
if (w->Z)
{
/* accumulate Z: Z -> ZG */
xv = gsl_matrix_column(w->Z, top + j);
yv = gsl_matrix_column(w->Z, top + j + 1);
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
}
} /* for (j = 0; j < N - 1; ++j) */
return GSL_SUCCESS;
} /* gen_qzstep() */
/*
gen_qzstep_d()
Perform an implicit double shift QZ step.
See Golub & Van Loan, "Matrix Computations" (3rd ed), algorithm 7.7.2
Inputs: H - upper Hessenberg matrix (at least 3-by-3)
R - upper triangular matrix (at least 3-by-3)
w - workspace
*/
static inline void
gen_qzstep_d(gsl_matrix *H, gsl_matrix *R, gsl_eigen_gen_workspace *w)
{
const size_t N = H->size1;
size_t j; /* looping */
double dat[3]; /* householder vector */
double tau; /* householder coefficient */
gsl_vector_view v2, v3; /* views into 'dat' */
gsl_matrix_view m; /* temporary view */
double tmp;
size_t q, r;
size_t top; /* location of H in original matrix */
double scale;
double AB11, /* various matrix element ratios */
AB22,
ABNN,
ABMM,
AMNBNN,
ANMBMM,
A21B11,
A12B22,
A32B22,
B12B22,
BMNBNN;
v2 = gsl_vector_view_array(dat, 2);
v3 = gsl_vector_view_array(dat, 3);
if (w->needtop)
{
/* get absolute index of this matrix relative to original matrix */
top = gen_get_submatrix(w->H, H);
}
/*
* Similar to the QR method, we take the shifts to be the two
* zeros of the problem
*
* det[H(n-1:n,n-1:n) - s*R(n-1:n,n-1:n)] = 0
*
* The initial householder vector elements are then given by
* Eq. 4.1 of [1], which are designed to reduce errors when
* off diagonal elements are small.
*/
ABMM = (w->ascale * gsl_matrix_get(H, N - 2, N - 2)) /
(w->bscale * gsl_matrix_get(R, N - 2, N - 2));
ABNN = (w->ascale * gsl_matrix_get(H, N - 1, N - 1)) /
(w->bscale * gsl_matrix_get(R, N - 1, N - 1));
AB11 = (w->ascale * gsl_matrix_get(H, 0, 0)) /
(w->bscale * gsl_matrix_get(R, 0, 0));
AB22 = (w->ascale * gsl_matrix_get(H, 1, 1)) /
(w->bscale * gsl_matrix_get(R, 1, 1));
AMNBNN = (w->ascale * gsl_matrix_get(H, N - 2, N - 1)) /
(w->bscale * gsl_matrix_get(R, N - 1, N - 1));
ANMBMM = (w->ascale * gsl_matrix_get(H, N - 1, N - 2)) /
(w->bscale * gsl_matrix_get(R, N - 2, N - 2));
BMNBNN = gsl_matrix_get(R, N - 2, N - 1) /
gsl_matrix_get(R, N - 1, N - 1);
A21B11 = (w->ascale * gsl_matrix_get(H, 1, 0)) /
(w->bscale * gsl_matrix_get(R, 0, 0));
A12B22 = (w->ascale * gsl_matrix_get(H, 0, 1)) /
(w->bscale * gsl_matrix_get(R, 1, 1));
A32B22 = (w->ascale * gsl_matrix_get(H, 2, 1)) /
(w->bscale * gsl_matrix_get(R, 1, 1));
B12B22 = gsl_matrix_get(R, 0, 1) / gsl_matrix_get(R, 1, 1);
/*
* These are the Eqs (4.1) of [1], just multiplied by the factor
* (A_{21} / B_{11})
*/
dat[0] = (ABMM - AB11) * (ABNN - AB11) - (AMNBNN * ANMBMM) +
(ANMBMM * BMNBNN * AB11) + (A12B22 - (AB11 * B12B22)) * A21B11;
dat[1] = ((AB22 - AB11) - (A21B11 * B12B22) - (ABMM - AB11) -
(ABNN - AB11) + (ANMBMM * BMNBNN)) * A21B11;
dat[2] = A32B22 * A21B11;
scale = fabs(dat[0]) + fabs(dat[1]) + fabs(dat[2]);
if (scale != 0.0)
{
dat[0] /= scale;
dat[1] /= scale;
dat[2] /= scale;
}
for (j = 0; j < N - 2; ++j)
{
r = GSL_MIN(j + 4, N);
/*
* Find householder Q so that
*
* Q [x y z]^t = [ * 0 0 ]^t
*/
tau = gsl_linalg_householder_transform(&v3.vector);
if (tau != 0.0)
{
/*
* q is the initial column to start applying the householder
* transformation. The GSL_MAX() simply ensures we don't
* try to apply it to column (-1), since we are zeroing out
* column (j - 1) except for the first iteration which
* introduces the bulge.
*/
q = (size_t) GSL_MAX(0, (int)j - 1);
/* H -> QH, R -> QR */
if (w->compute_s)
{
/*
* We are computing the Schur form S, so we need to
* transform the whole matrix H
*/
m = gsl_matrix_submatrix(w->H,
top + j,
top + q,
3,
w->size - top - q);
gsl_linalg_householder_hm(tau, &v3.vector, &m.matrix);
}
else
{
/* just transform the active block */
m = gsl_matrix_submatrix(H, j, q, 3, N - q);
gsl_linalg_householder_hm(tau, &v3.vector, &m.matrix);
}
if (w->compute_t)
{
/*
* We are computing the Schur form T, so we need to
* transform the whole matrix R
*/
m = gsl_matrix_submatrix(w->R,
top + j,
top + j,
3,
w->size - top - j);
gsl_linalg_householder_hm(tau, &v3.vector, &m.matrix);
}
else
{
/* just transform the active block */
m = gsl_matrix_submatrix(R, j, j, 3, N - j);
gsl_linalg_householder_hm(tau, &v3.vector, &m.matrix);
}
if (w->Q)
{
/* accumulate the transformation into Q */
m = gsl_matrix_submatrix(w->Q, 0, top + j, w->size, 3);
gsl_linalg_householder_mh(tau, &v3.vector, &m.matrix);
}
} /* if (tau != 0.0) */
/*
* Find householder Z so that
*
* [ r_{j+2,j} r_{j+2, j+1}, r_{j+2, j+2} ] Z = [ 0 0 * ]
*
* This isn't exactly what gsl_linalg_householder_transform
* does, so we need to rotate the input vector so it preserves
* the last element, and then rotate it back afterwards.
*
* So instead of transforming [x y z], we transform [z x y],
* and the resulting HH vector [1 v2 v3] -> [v2 v3 1] but
* then needs to be scaled to have the first element = 1, so
* it becomes [1 v3/v2 1/v2] (tau must also be scaled accordingly).
*/
dat[0] = gsl_matrix_get(R, j + 2, j + 2);
dat[1] = gsl_matrix_get(R, j + 2, j);
dat[2] = gsl_matrix_get(R, j + 2, j + 1);
scale = fabs(dat[0]) + fabs(dat[1]) + fabs(dat[2]);
if (scale != 0.0)
{
dat[0] /= scale;
dat[1] /= scale;
dat[2] /= scale;
}
tau = gsl_linalg_householder_transform(&v3.vector);
if (tau != 0.0)
{
/* rotate back */
tmp = gsl_vector_get(&v3.vector, 1);
gsl_vector_set(&v3.vector, 1, gsl_vector_get(&v3.vector, 2)/tmp);
gsl_vector_set(&v3.vector, 2, 1.0 / tmp);
tau *= tmp * tmp;
/* H -> HZ, R -> RZ */
if (w->compute_s)
{
m = gsl_matrix_submatrix(w->H, 0, top + j, top + r, 3);
gsl_linalg_householder_mh(tau, &v3.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(H, 0, j, r, 3);
gsl_linalg_householder_mh(tau, &v3.vector, &m.matrix);
}
if (w->compute_t)
{
m = gsl_matrix_submatrix(w->R, 0, top + j, top + j + 3, 3);
gsl_linalg_householder_mh(tau, &v3.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(R, 0, j, j + 3, 3);
gsl_linalg_householder_mh(tau, &v3.vector, &m.matrix);
}
if (w->Z)
{
/* accumulate transformation into Z */
m = gsl_matrix_submatrix(w->Z, 0, top + j, w->size, 3);
gsl_linalg_householder_mh(tau, &v3.vector, &m.matrix);
}
} /* if (tau != 0.0) */
/*
* Find householder Z so that
*
* [ r_{j+1,j} r_{j+1, j+1} ] Z = [ 0 * ]
*/
dat[0] = gsl_matrix_get(R, j + 1, j + 1);
dat[1] = gsl_matrix_get(R, j + 1, j);
scale = fabs(dat[0]) + fabs(dat[1]);
if (scale != 0.0)
{
dat[0] /= scale;
dat[1] /= scale;
}
tau = gsl_linalg_householder_transform(&v2.vector);
if (tau != 0.0)
{
/* rotate back */
tmp = gsl_vector_get(&v2.vector, 1);
gsl_vector_set(&v2.vector, 1, 1.0 / tmp);
tau *= tmp * tmp;
/* H -> HZ, R -> RZ */
if (w->compute_s)
{
m = gsl_matrix_submatrix(w->H, 0, top + j, top + r, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(H, 0, j, r, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
if (w->compute_t)
{
m = gsl_matrix_submatrix(w->R, 0, top + j, top + j + 3, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(R, 0, j, j + 3, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
if (w->Z)
{
/* accumulate transformation into Z */
m = gsl_matrix_submatrix(w->Z, 0, top + j, w->size, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
} /* if (tau != 0.0) */
dat[0] = gsl_matrix_get(H, j + 1, j);
dat[1] = gsl_matrix_get(H, j + 2, j);
if (j < N - 3)
dat[2] = gsl_matrix_get(H, j + 3, j);
scale = fabs(dat[0]) + fabs(dat[1]) + fabs(dat[2]);
if (scale != 0.0)
{
dat[0] /= scale;
dat[1] /= scale;
dat[2] /= scale;
}
} /* for (j = 0; j < N - 2; ++j) */
/*
* Find Householder Q so that
*
* Q [ x y ]^t = [ * 0 ]^t
*/
scale = fabs(dat[0]) + fabs(dat[1]);
if (scale != 0.0)
{
dat[0] /= scale;
dat[1] /= scale;
}
tau = gsl_linalg_householder_transform(&v2.vector);
if (w->compute_s)
{
m = gsl_matrix_submatrix(w->H,
top + N - 2,
top + N - 3,
2,
w->size - top - N + 3);
gsl_linalg_householder_hm(tau, &v2.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(H, N - 2, N - 3, 2, 3);
gsl_linalg_householder_hm(tau, &v2.vector, &m.matrix);
}
if (w->compute_t)
{
m = gsl_matrix_submatrix(w->R,
top + N - 2,
top + N - 2,
2,
w->size - top - N + 2);
gsl_linalg_householder_hm(tau, &v2.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(R, N - 2, N - 2, 2, 2);
gsl_linalg_householder_hm(tau, &v2.vector, &m.matrix);
}
if (w->Q)
{
/* accumulate the transformation into Q */
m = gsl_matrix_submatrix(w->Q, 0, top + N - 2, w->size, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
/*
* Find Householder Z so that
*
* [ b_{n,n-1} b_{nn} ] Z = [ 0 * ]
*/
dat[0] = gsl_matrix_get(R, N - 1, N - 1);
dat[1] = gsl_matrix_get(R, N - 1, N - 2);
scale = fabs(dat[0]) + fabs(dat[1]);
if (scale != 0.0)
{
dat[0] /= scale;
dat[1] /= scale;
}
tau = gsl_linalg_householder_transform(&v2.vector);
/* rotate back */
tmp = gsl_vector_get(&v2.vector, 1);
gsl_vector_set(&v2.vector, 1, 1.0 / tmp);
tau *= tmp * tmp;
if (w->compute_s)
{
m = gsl_matrix_submatrix(w->H, 0, top + N - 2, top + N, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(H, 0, N - 2, N, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
if (w->compute_t)
{
m = gsl_matrix_submatrix(w->R, 0, top + N - 2, top + N, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
else
{
m = gsl_matrix_submatrix(R, 0, N - 2, N, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
if (w->Z)
{
/* accumulate the transformation into Z */
m = gsl_matrix_submatrix(w->Z, 0, top + N - 2, w->size, 2);
gsl_linalg_householder_mh(tau, &v2.vector, &m.matrix);
}
} /* gen_qzstep_d() */
/*
gen_tri_split_top()
This routine is called when the leading element on the diagonal of R
has become negligible. Split off a 1-by-1 block at the top.
Inputs: H - upper hessenberg matrix
R - upper triangular matrix
w - workspace
*/
static void
gen_tri_split_top(gsl_matrix *H, gsl_matrix *R, gsl_eigen_gen_workspace *w)
{
const size_t N = H->size1;
size_t j, top;
double cs, sn;
gsl_vector_view xv, yv;
if (w->needtop)
top = gen_get_submatrix(w->H, H);
j = 0;
create_givens(gsl_matrix_get(H, j, j),
gsl_matrix_get(H, j + 1, j),
&cs,
&sn);
sn = -sn;
if (w->compute_s)
{
xv = gsl_matrix_subrow(w->H, top + j, top, w->size - top);
yv = gsl_matrix_subrow(w->H, top + j + 1, top, w->size - top);
}
else
{
xv = gsl_matrix_row(H, j);
yv = gsl_matrix_row(H, j + 1);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
gsl_matrix_set(H, j + 1, j, 0.0);
if (w->compute_t)
{
xv = gsl_matrix_subrow(w->R, top + j, top + 1, w->size - top - 1);
yv = gsl_matrix_subrow(w->R, top + j + 1, top + 1, w->size - top - 1);
}
else
{
xv = gsl_matrix_subrow(R, j, 1, N - 1);
yv = gsl_matrix_subrow(R, j + 1, 1, N - 1);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
if (w->Q)
{
xv = gsl_matrix_column(w->Q, top + j);
yv = gsl_matrix_column(w->Q, top + j + 1);
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
}
} /* gen_tri_split_top() */
/*
gen_tri_chase_zero()
This routine is called when an element on the diagonal of R
has become negligible. Chase the zero to the bottom of the active
block so we can split off a 1-by-1 block.
Inputs: H - upper hessenberg matrix
R - upper triangular matrix
q - index such that R(q,q) = 0 (q must be > 0)
w - workspace
*/
static inline void
gen_tri_chase_zero(gsl_matrix *H, gsl_matrix *R, size_t q,
gsl_eigen_gen_workspace *w)
{
const size_t N = H->size1;
size_t j, top;
double cs, sn;
gsl_vector_view xv, yv;
if (w->needtop)
top = gen_get_submatrix(w->H, H);
for (j = q; j < N - 1; ++j)
{
create_givens(gsl_matrix_get(R, j, j + 1),
gsl_matrix_get(R, j + 1, j + 1),
&cs,
&sn);
sn = -sn;
if (w->compute_t)
{
xv = gsl_matrix_subrow(w->R, top + j, top + j + 1, w->size - top - j - 1);
yv = gsl_matrix_subrow(w->R, top + j + 1, top + j + 1, w->size - top - j - 1);
}
else
{
xv = gsl_matrix_subrow(R, j, j + 1, N - j - 1);
yv = gsl_matrix_subrow(R, j + 1, j + 1, N - j - 1);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
gsl_matrix_set(R, j + 1, j + 1, 0.0);
if (w->compute_s)
{
xv = gsl_matrix_subrow(w->H, top + j, top + j - 1, w->size - top - j + 1);
yv = gsl_matrix_subrow(w->H, top + j + 1, top + j - 1, w->size - top - j + 1);
}
else
{
xv = gsl_matrix_subrow(H, j, j - 1, N - j + 1);
yv = gsl_matrix_subrow(H, j + 1, j - 1, N - j + 1);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
if (w->Q)
{
/* accumulate Q */
xv = gsl_matrix_column(w->Q, top + j);
yv = gsl_matrix_column(w->Q, top + j + 1);
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
}
create_givens(gsl_matrix_get(H, j + 1, j),
gsl_matrix_get(H, j + 1, j - 1),
&cs,
&sn);
sn = -sn;
if (w->compute_s)
{
xv = gsl_matrix_subcolumn(w->H, top + j, 0, top + j + 2);
yv = gsl_matrix_subcolumn(w->H, top + j - 1, 0, top + j + 2);
}
else
{
xv = gsl_matrix_subcolumn(H, j, 0, j + 2);
yv = gsl_matrix_subcolumn(H, j - 1, 0, j + 2);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
gsl_matrix_set(H, j + 1, j - 1, 0.0);
if (w->compute_t)
{
xv = gsl_matrix_subcolumn(w->R, top + j, 0, top + j + 1);
yv = gsl_matrix_subcolumn(w->R, top + j - 1, 0, top + j + 1);
}
else
{
xv = gsl_matrix_subcolumn(R, j, 0, j + 1);
yv = gsl_matrix_subcolumn(R, j - 1, 0, j + 1);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
if (w->Z)
{
/* accumulate Z */
xv = gsl_matrix_column(w->Z, top + j);
yv = gsl_matrix_column(w->Z, top + j - 1);
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
}
}
} /* gen_tri_chase_zero() */
/*
gen_tri_zero_H()
Companion function to get_tri_chase_zero(). After the zero on
the diagonal of R has been chased to the bottom, we zero the element
H(n, n - 1) in order to split off a 1-by-1 block.
*/
static inline void
gen_tri_zero_H(gsl_matrix *H, gsl_matrix *R, gsl_eigen_gen_workspace *w)
{
const size_t N = H->size1;
size_t top;
double cs, sn;
gsl_vector_view xv, yv;
if (w->needtop)
top = gen_get_submatrix(w->H, H);
create_givens(gsl_matrix_get(H, N - 1, N - 1),
gsl_matrix_get(H, N - 1, N - 2),
&cs,
&sn);
sn = -sn;
if (w->compute_s)
{
xv = gsl_matrix_subcolumn(w->H, top + N - 1, 0, top + N);
yv = gsl_matrix_subcolumn(w->H, top + N - 2, 0, top + N);
}
else
{
xv = gsl_matrix_column(H, N - 1);
yv = gsl_matrix_column(H, N - 2);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
gsl_matrix_set(H, N - 1, N - 2, 0.0);
if (w->compute_t)
{
xv = gsl_matrix_subcolumn(w->R, top + N - 1, 0, top + N - 1);
yv = gsl_matrix_subcolumn(w->R, top + N - 2, 0, top + N - 1);
}
else
{
xv = gsl_matrix_subcolumn(R, N - 1, 0, N - 1);
yv = gsl_matrix_subcolumn(R, N - 2, 0, N - 1);
}
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
if (w->Z)
{
/* accumulate Z */
xv = gsl_matrix_column(w->Z, top + N - 1);
yv = gsl_matrix_column(w->Z, top + N - 2);
gsl_blas_drot(&xv.vector, &yv.vector, cs, sn);
}
} /* gen_tri_zero_H() */
/*
gen_search_small_elements()
This routine searches for small elements in the matrix pencil
(H, R) to determine if any eigenvalues have converged.
Tests:
1. Test if the Hessenberg matrix has a small subdiagonal element:
H(i, i - 1) < tolerance
2. Test if the Triangular matrix has a small diagonal element:
R(i, i) < tolerance
Possible outcomes:
(A) Neither test passed: in this case 'flag' is set to 0 and the
function returns 0
(B) Test 1 passes and 2 does not: in this case 'flag' is set to 1
and we return the row index i such that H(i, i - 1) < tol
(C) Test 2 passes and 1 does not: in this case 'flag' is set to 2
and we return the index i such that R(i, i) < tol
(D) Tests 1 and 2 both pass: in this case 'flag' is set to 3 and
we return the index i such that H(i, i - 1) < tol and R(i, i) < tol
Inputs: H - upper Hessenberg matrix
R - upper Triangular matrix
flag - (output) flag set on output (see above)
w - workspace
Return: see above
*/
static inline size_t
gen_search_small_elements(gsl_matrix *H, gsl_matrix *R,
int *flag, gsl_eigen_gen_workspace *w)
{
const size_t N = H->size1;
int k;
size_t i;
int pass1 = 0;
int pass2 = 0;
for (k = (int) N - 1; k >= 0; --k)
{
i = (size_t) k;
if (i != 0 && fabs(gsl_matrix_get(H, i, i - 1)) <= w->atol)
{
gsl_matrix_set(H, i, i - 1, 0.0);
pass1 = 1;
}
if (fabs(gsl_matrix_get(R, i, i)) < w->btol)
{
gsl_matrix_set(R, i, i, 0.0);
pass2 = 1;
}
if (pass1 && !pass2) /* case B */
{
*flag = 1;
return (i);
}
else if (!pass1 && pass2) /* case C */
{
*flag = 2;
return (i);
}
else if (pass1 && pass2) /* case D */
{
*flag = 3;
return (i);
}
}
/* neither test passed: case A */
*flag = 0;
return (0);
} /* gen_search_subdiag_small_elements() */
/*
gen_schur_standardize1()
This function is called when a 1-by-1 block has converged -
convert the block to standard form and update the Schur forms and
vectors if required. Standard form here means that the diagonal
element of B is positive.
Inputs: A - 1-by-1 matrix in Schur form S
B - 1-by-1 matrix in Schur form T
alphar - where to store real part of eigenvalue numerator
beta - where to store eigenvalue denominator
w - workspace
Return: success
*/
static int
gen_schur_standardize1(gsl_matrix *A, gsl_matrix *B, double *alphar,
double *beta, gsl_eigen_gen_workspace *w)
{
size_t i;
size_t top;
/*
* it is a 1-by-1 block - the only requirement is that
* B_{00} is > 0, so if it isn't apply a -I transformation
*/
if (gsl_matrix_get(B, 0, 0) < 0.0)
{
if (w->needtop)
top = gen_get_submatrix(w->H, A);
if (w->compute_t)
{
for (i = 0; i <= top; ++i)
gsl_matrix_set(w->R, i, top, -gsl_matrix_get(w->R, i, top));
}
else
gsl_matrix_set(B, 0, 0, -gsl_matrix_get(B, 0, 0));
if (w->compute_s)
{
for (i = 0; i <= top; ++i)
gsl_matrix_set(w->H, i, top, -gsl_matrix_get(w->H, i, top));
}
else
gsl_matrix_set(A, 0, 0, -gsl_matrix_get(A, 0, 0));
if (w->Z)
{
for (i = 0; i < w->size; ++i)
gsl_matrix_set(w->Z, i, top, -gsl_matrix_get(w->Z, i, top));
}
}
*alphar = gsl_matrix_get(A, 0, 0);
*beta = gsl_matrix_get(B, 0, 0);
return GSL_SUCCESS;
} /* gen_schur_standardize1() */
/*
gen_schur_standardize2()
This function is called when a 2-by-2 generalized block has
converged. Convert the block to standard form, which means B
is rotated so that
B = [ B11 0 ] with B11, B22 non-negative
[ 0 B22 ]
If the resulting block (A, B) has complex eigenvalues, they are
computed. Otherwise, the function will return GSL_CONTINUE to
notify caller that we need to do more single shift sweeps to
convert the 2-by-2 block into two 1-by-1 blocks.
Inputs: A - 2-by-2 submatrix of schur form S
B - 2-by-2 submatrix of schur form T
alpha1 - (output) where to store eigenvalue 1 numerator
alpha2 - (output) where to store eigenvalue 2 numerator
beta1 - (output) where to store eigenvalue 1 denominator
beta2 - (output) where to store eigenvalue 2 denominator
w - workspace
Return: GSL_SUCCESS if block has complex eigenvalues (they are computed)
GSL_CONTINUE if block has real eigenvalues (they are not computed)
*/
static int
gen_schur_standardize2(gsl_matrix *A, gsl_matrix *B, gsl_complex *alpha1,
gsl_complex *alpha2, double *beta1, double *beta2,
gsl_eigen_gen_workspace *w)
{
double datB[4],
datV[4],
datS[2],
work[2];
gsl_matrix_view uv = gsl_matrix_view_array(datB, 2, 2);
gsl_matrix_view vv = gsl_matrix_view_array(datV, 2, 2);
gsl_vector_view sv = gsl_vector_view_array(datS, 2);
gsl_vector_view wv = gsl_vector_view_array(work, 2);
double B11, B22;
size_t top;
double det;
double cr, sr, cl, sl;
gsl_vector_view xv, yv;
int s;
if (w->needtop)
top = gen_get_submatrix(w->H, A);
/*
* Rotate B so that
*
* B = [ B11 0 ]
* [ 0 B22 ]
*
* with B11 non-negative
*/
gsl_matrix_memcpy(&uv.matrix, B);
gsl_linalg_SV_decomp(&uv.matrix, &vv.matrix, &sv.vector, &wv.vector);
/*
* Right now, B = U S V^t, where S = diag(s)
*
* The SVD routine may have computed reflection matrices U and V,
* but it would be much nicer to have rotations since we won't have
* to use BLAS mat-mat multiplications to update our matrices,
* and can instead use drot. So convert them to rotations if
* necessary
*/
det = gsl_matrix_get(&vv.matrix, 0, 0) * gsl_matrix_get(&vv.matrix, 1, 1) -
gsl_matrix_get(&vv.matrix, 0, 1) * gsl_matrix_get(&vv.matrix, 1, 0);
if (det < 0.0)
{
/* V is a reflection, convert it to a rotation by inserting
* F = [1 0; 0 -1] so that:
*
* B = U S [1 0] [1 0] V^t
* [0 -1] [0 -1]
*
* so S -> S F and V -> V F where F is the reflection matrix
* We just need to invert S22 since the first column of V
* will remain unchanged and we can just read off the CS and SN
* parameters.
*/
datS[1] = -datS[1];
}
cr = gsl_matrix_get(&vv.matrix, 0, 0);
sr = gsl_matrix_get(&vv.matrix, 1, 0);
/* same for U */
det = gsl_matrix_get(&uv.matrix, 0, 0) * gsl_matrix_get(&uv.matrix, 1, 1) -
gsl_matrix_get(&uv.matrix, 0, 1) * gsl_matrix_get(&uv.matrix, 1, 0);
if (det < 0.0)
datS[1] = -datS[1];
cl = gsl_matrix_get(&uv.matrix, 0, 0);
sl = gsl_matrix_get(&uv.matrix, 1, 0);
B11 = gsl_vector_get(&sv.vector, 0);
B22 = gsl_vector_get(&sv.vector, 1);
/* make sure B11 is positive */
if (B11 < 0.0)
{
B11 = -B11;
B22 = -B22;
cr = -cr;
sr = -sr;
}
/*
* At this point,
*
* [ S11 0 ] = [ CSL SNL ] B [ CSR -SNR ]
* [ 0 S22 ] [-SNL CSL ] [ SNR CSR ]
*
* apply rotations to H and rest of R
*/
if (w->compute_s)
{
xv = gsl_matrix_subrow(w->H, top, top, w->size - top);
yv = gsl_matrix_subrow(w->H, top + 1, top, w->size - top);
gsl_blas_drot(&xv.vector, &yv.vector, cl, sl);
xv = gsl_matrix_subcolumn(w->H, top, 0, top + 2);
yv = gsl_matrix_subcolumn(w->H, top + 1, 0, top + 2);
gsl_blas_drot(&xv.vector, &yv.vector, cr, sr);
}
else
{
xv = gsl_matrix_row(A, 0);
yv = gsl_matrix_row(A, 1);
gsl_blas_drot(&xv.vector, &yv.vector, cl, sl);
xv = gsl_matrix_column(A, 0);
yv = gsl_matrix_column(A, 1);
gsl_blas_drot(&xv.vector, &yv.vector, cr, sr);
}
if (w->compute_t)
{
if (top != (w->size - 2))
{
xv = gsl_matrix_subrow(w->R, top, top + 2, w->size - top - 2);
yv = gsl_matrix_subrow(w->R, top + 1, top + 2, w->size - top - 2);
gsl_blas_drot(&xv.vector, &yv.vector, cl, sl);
}
if (top != 0)
{
xv = gsl_matrix_subcolumn(w->R, top, 0, top);
yv = gsl_matrix_subcolumn(w->R, top + 1, 0, top);
gsl_blas_drot(&xv.vector, &yv.vector, cr, sr);
}
}
if (w->Q)
{
xv = gsl_matrix_column(w->Q, top);
yv = gsl_matrix_column(w->Q, top + 1);
gsl_blas_drot(&xv.vector, &yv.vector, cl, sl);
}
if (w->Z)
{
xv = gsl_matrix_column(w->Z, top);
yv = gsl_matrix_column(w->Z, top + 1);
gsl_blas_drot(&xv.vector, &yv.vector, cr, sr);
}
gsl_matrix_set(B, 0, 0, B11);
gsl_matrix_set(B, 0, 1, 0.0);
gsl_matrix_set(B, 1, 0, 0.0);
gsl_matrix_set(B, 1, 1, B22);
/* if B22 is < 0, make it positive by negating its column */
if (B22 < 0.0)
{
size_t i;
if (w->compute_s)
{
for (i = 0; i < top + 2; ++i)
gsl_matrix_set(w->H, i, top + 1, -gsl_matrix_get(w->H, i, top + 1));
}
else
{
gsl_matrix_set(A, 0, 1, -gsl_matrix_get(A, 0, 1));
gsl_matrix_set(A, 1, 1, -gsl_matrix_get(A, 1, 1));
}
if (w->compute_t)
{
for (i = 0; i < top + 2; ++i)
gsl_matrix_set(w->R, i, top + 1, -gsl_matrix_get(w->R, i, top + 1));
}
else
{
gsl_matrix_set(B, 0, 1, -gsl_matrix_get(B, 0, 1));
gsl_matrix_set(B, 1, 1, -gsl_matrix_get(B, 1, 1));
}
if (w->Z)
{
xv = gsl_matrix_column(w->Z, top + 1);
gsl_vector_scale(&xv.vector, -1.0);
}
}
/* our block is now in standard form - compute eigenvalues */
s = gen_compute_eigenvals(A, B, alpha1, alpha2, beta1, beta2);
return s;
} /* gen_schur_standardize2() */
/*
gen_compute_eigenvals()
Compute the complex eigenvalues of a 2-by-2 block
Return: GSL_CONTINUE if block contains real eigenvalues (they are not
computed)
GSL_SUCCESS on normal completion
*/
static int
gen_compute_eigenvals(gsl_matrix *A, gsl_matrix *B, gsl_complex *alpha1,
gsl_complex *alpha2, double *beta1, double *beta2)
{
double wr1, wr2, wi, scale1, scale2;
double s1inv;
double A11, A12, A21, A22;
double B11, B22;
double c11r, c11i, c12, c21, c22r, c22i;
double cz, cq;
double szr, szi, sqr, sqi;
double a1r, a1i, a2r, a2i, b1r, b1i, b1a, b2r, b2i, b2a;
double alphar, alphai;
double t1, an, bn, tempr, tempi, wabs;
/*
* This function is called from gen_schur_standardize2() and
* its possible the standardization has perturbed the eigenvalues
* onto the real line - so check for this before computing them
*/
gsl_schur_gen_eigvals(A, B, &wr1, &wr2, &wi, &scale1, &scale2);
if (wi == 0.0)
return GSL_CONTINUE; /* real eigenvalues - continue QZ iteration */
/* complex eigenvalues - compute alpha and beta */
s1inv = 1.0 / scale1;
A11 = gsl_matrix_get(A, 0, 0);
A12 = gsl_matrix_get(A, 0, 1);
A21 = gsl_matrix_get(A, 1, 0);
A22 = gsl_matrix_get(A, 1, 1);
B11 = gsl_matrix_get(B, 0, 0);
B22 = gsl_matrix_get(B, 1, 1);
c11r = scale1 * A11 - wr1 * B11;
c11i = -wi * B11;
c12 = scale1 * A12;
c21 = scale1 * A21;
c22r = scale1 * A22 - wr1 * B22;
c22i = -wi * B22;
if (fabs(c11r) + fabs(c11i) + fabs(c12) >
fabs(c21) + fabs(c22r) + fabs(c22i))
{
t1 = gsl_hypot3(c12, c11r, c11i);
if (t1 != 0.0)
{
cz = c12 / t1;
szr = -c11r / t1;
szi = -c11i / t1;
}
else
{
cz = 0.0;
szr = 1.0;
szi = 0.0;
}
}
else
{
cz = hypot(c22r, c22i);
if (cz <= GSL_DBL_MIN)
{
cz = 0.0;
szr = 1.0;
szi = 0.0;
}
else
{
tempr = c22r / cz;
tempi = c22i / cz;
t1 = hypot(cz, c21);
cz /= t1;
szr = -c21*tempr / t1;
szi = c21*tempi / t1;
}
}
an = fabs(A11) + fabs(A12) + fabs(A21) + fabs(A22);
bn = fabs(B11) + fabs(B22);
wabs = fabs(wr1) + fabs(wi);
if (scale1*an > wabs*bn)
{
cq = cz * B11;
if (cq <= GSL_DBL_MIN)
{
cq = 0.0;
sqr = 1.0;
sqi = 0.0;
}
else
{
sqr = szr * B22;
sqi = -szi * B22;
}
}
else
{
a1r = cz * A11 + szr * A12;
a1i = szi * A12;
a2r = cz * A21 + szr * A22;
a2i = szi * A22;
cq = hypot(a1r, a1i);
if (cq <= GSL_DBL_MIN)
{
cq = 0.0;
sqr = 1.0;
sqi = 0.0;
}
else
{
tempr = a1r / cq;
tempi = a1i / cq;
sqr = tempr * a2r + tempi * a2i;
sqi = tempi * a2r - tempr * a2i;
}
}
t1 = gsl_hypot3(cq, sqr, sqi);
cq /= t1;
sqr /= t1;
sqi /= t1;
tempr = sqr*szr - sqi*szi;
tempi = sqr*szi + sqi*szr;
b1r = cq*cz*B11 + tempr*B22;
b1i = tempi*B22;
b1a = hypot(b1r, b1i);
b2r = cq*cz*B22 + tempr*B11;
b2i = -tempi*B11;
b2a = hypot(b2r, b2i);
*beta1 = b1a;
*beta2 = b2a;
alphar = (wr1 * b1a) * s1inv;
alphai = (wi * b1a) * s1inv;
GSL_SET_COMPLEX(alpha1, alphar, alphai);
alphar = (wr1 * b2a) * s1inv;
alphai = -(wi * b2a) * s1inv;
GSL_SET_COMPLEX(alpha2, alphar, alphai);
return GSL_SUCCESS;
} /* gen_compute_eigenvals() */
/*
gen_store_eigval1()
Store eigenvalue of a 1-by-1 block into the alpha and beta
output vectors. This routine ensures that eigenvalues are stored
in the same order as they appear in the Schur form and updates
various internal workspace quantities.
*/
static void
gen_store_eigval1(const gsl_matrix *H, const double a, const double b,
gsl_vector_complex *alpha,
gsl_vector *beta, gsl_eigen_gen_workspace *w)
{
size_t top = gen_get_submatrix(w->H, H);
gsl_complex z;
GSL_SET_COMPLEX(&z, a, 0.0);
gsl_vector_complex_set(alpha, top, z);
gsl_vector_set(beta, top, b);
w->n_evals += 1;
w->n_iter = 0;
w->eshift = 0.0;
} /* gen_store_eigval1() */
/*
gen_store_eigval2()
Store eigenvalues of a 2-by-2 block into the alpha and beta
output vectors. This routine ensures that eigenvalues are stored
in the same order as they appear in the Schur form and updates
various internal workspace quantities.
*/
static void
gen_store_eigval2(const gsl_matrix *H, const gsl_complex *alpha1,
const double beta1, const gsl_complex *alpha2,
const double beta2, gsl_vector_complex *alpha,
gsl_vector *beta, gsl_eigen_gen_workspace *w)
{
size_t top = gen_get_submatrix(w->H, H);
gsl_vector_complex_set(alpha, top, *alpha1);
gsl_vector_set(beta, top, beta1);
gsl_vector_complex_set(alpha, top + 1, *alpha2);
gsl_vector_set(beta, top + 1, beta2);
w->n_evals += 2;
w->n_iter = 0;
w->eshift = 0.0;
} /* gen_store_eigval2() */
/*
gen_get_submatrix()
B is a submatrix of A. The goal of this function is to
compute the indices in A of where the matrix B resides
*/
static inline size_t
gen_get_submatrix(const gsl_matrix *A, const gsl_matrix *B)
{
size_t diff;
double ratio;
size_t top;
diff = (size_t) (B->data - A->data);
/* B is on the diagonal of A, so measure distance in units of
tda+1 */
ratio = (double)diff / ((double) (A->tda + 1));
top = (size_t) floor(ratio);
return top;
} /* gen_get_submatrix() */
/* Frobenius norm */
inline static double
normF (gsl_matrix * A)
{
size_t i, j, M = A->size1, N = A->size2;
double sum = 0.0, scale = 0.0, ssq = 1.0;
for (i = 0; i < M; i++)
{
for (j = 0; j < N; j++)
{
double Aij = gsl_matrix_get (A, i, j);
if (Aij != 0.0)
{
double ax = fabs (Aij);
if (scale < ax)
{
ssq = 1.0 + ssq * (scale / ax) * (scale / ax);
scale = ax;
}
else
{
ssq += (ax / scale) * (ax / scale);
}
}
}
}
sum = scale * sqrt (ssq);
return sum;
}
/* Generate a Givens rotation (cos,sin) which takes v=(x,y) to (|v|,0)
From Golub and Van Loan, "Matrix Computations", Section 5.1.8 */
inline static void
create_givens (const double a, const double b, double *c, double *s)
{
if (b == 0)
{
*c = 1;
*s = 0;
}
else if (fabs (b) > fabs (a))
{
double t = -a / b;
double s1 = 1.0 / sqrt (1 + t * t);
*s = s1;
*c = s1 * t;
}
else
{
double t = -b / a;
double c1 = 1.0 / sqrt (1 + t * t);
*c = c1;
*s = c1 * t;
}
}
| {
"alphanum_fraction": 0.5199993402,
"avg_line_length": 28.6381672178,
"ext": "c",
"hexsha": "0a033573e77b24c24232a951a7a3bdcb97317a84",
"lang": "C",
"max_forks_count": 14,
"max_forks_repo_forks_event_max_datetime": "2020-03-12T12:31:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T04:47:52.000Z",
"max_forks_repo_head_hexsha": "0cb4635af7602f2a243a9b739e5ed757424ab2a7",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "skair39/structured",
"max_forks_repo_path": "CMVS-PMVS/program/thirdParty/gsl-1.13/eigen/gen.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0cb4635af7602f2a243a9b739e5ed757424ab2a7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "skair39/structured",
"max_issues_repo_path": "CMVS-PMVS/program/thirdParty/gsl-1.13/eigen/gen.c",
"max_line_length": 88,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "2ad5bfb9c9684b1c800e96732a9e2f1e844b856f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "ruslankuzmin/julia",
"max_stars_repo_path": "oldjuila/juliakernel/ext_libraries/gsl/eigen/gen.c",
"max_stars_repo_stars_event_max_datetime": "2021-11-25T17:31:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-11T02:53:04.000Z",
"num_tokens": 18620,
"size": 60627
} |
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@file tirific.c
@brief Translation and recreation of tirific.f
Is a code to apply simulated annealing fitting datacubes to a cube, currently in the gipsy environment.
Guideline how to hack into it, without a guarantee:
Check: interpinit, interpover
This was commented hdu stuff
i) Introducing a new singular parameter:
1. Chose a struct of the four loginf headerinf ringparms and fitparms to include the parameter as a component.
2. Add the parameter into the identifyer list: Add the parameter identifyer as the last element in the first PRIMPOS list (after comment "Not in first header" but before "Third hdu"). Change all numbers in the PRIMPOS list (also after the comment) such that the numbers following the added identifyer are increased by 1. Increase the PRIMHDN_SINGLE symbolic constant by 1.
3. Change the functions primpos_numtype() and primpos_value() hdl_init() by adding the new parameter at exactly the same place that it was added to the identifyer list.
4. Go into the get_hdrinf(), get_loginf(), get_ringparms(), get_fitparms() functions and include the io of the parameter.
5. Change the code as you like.
ii) Introducing a new parameter for the second hdu (fit parameters)
1. The place to add the parameter as a new component is the varlel struct
2. Add the parameter into the identifyer list: Add the parameter identifyer as the last element in the second PRIMPOS list (before comment ""). Change all numbers in the PRIMPOS list (also after the comment) such that the numbers following the added identifyer are increased by 1. Include the parameter as a symbolic constant in the the _SECPOS list. Increase PRIMHDN_SINGLE symbolic constant by 1 and the SECHDN_MULTI by 1.
3. Change the functions primpos_numtype() and primpos_value() hdl_init() by adding the new parameter at exactly the same place that it was added to the identifyer list.
4. Check the functions get_fitparms(), secpos_value(), fillhdvarele() for a correct handling of the new parameter, best by simply copying the lines concerning another parameter.
5. That should be it. The parameter will be read and written and you can do what you like with it.
iii) Introducing a new parameter for the third hdu
1. Chose a struct of the four loginf headerinf ringparms and fitparms to include the parameter as a component, most likely to chose is the loginf struct that contains information about io.
2. Add the parameter into the identifyer list: Add the parameter identifyer as the last element in the first PRIMPOS list (after comment "Third hdu"). Change all numbers in the PRIMPOS list (also after the comment) such that the numbers following the added identifyer are increased by 1. Increase the PRIMHDN_SINGLE symbolic constant by 1. Add in the same way a new identifyer to the _TABNR list and change the constant OUTTABNR
3. Change the functions primpos_numtype() and primpos_value() hdl_init() by adding the new parameter at exactly the same place that it was added to the identifyer list.
4. Check the functions prepout(), writeoutput(), open_hdu_3, create_hdu_3(), writeasctable() (Only a suggestion).
5. Change the code as you like.
iv) Adding a completely new ring parameter (such as dispersion)
1. The place to add the parameter as a new component is the ringparms struct.
2. Add the parameter into the identifyer list: Add the parameter identifyer as the last element in the PXXXXX and XXXXX list. If it is a single parameter, change the NSPARAMS by adding 1, if it is a parameter for all rings, add 1 to the NPARAMS symbolic constant.
3. Change the function hdl_init() by adding the new parameter at exactly the same place that it was added to the identifyer list.
4. Check the functions dparamtointern(), dinterntoparam(), simpleinterntoglob(), simpleglobtointern(), globtointern(), interntoglob(), changetointern(), get_ringparms(), writeoutarray() for a correct handling of the new parameter. Check the graphics descriptor functions gr_ ...
5. That should be it. The parameter will be read and written and you can do what you like with it.
@todo check if the position ange read from dataset is correct
@todo think about the degrees of freedom at the start of metropolis
@todo check for leakage about line 5000 (varlel ll may not be deallocated properly)
@todo removed the automatic logfile length control in function open_hdu3() for stability reasons (it doesn't work) This has to be checked.
@todo Made logfile specification necessary to run tirific, because it doesn't run properly without a logfile. Before searching bugs, check whether the possibility not to have a logfile should be removed entirely.
@todo Error source sorting the file at the end of histout? Probably not...
@todo coolgal was not working, for some inexplicable reason the program crashed calling convolgaussfft in gridnconvol. The temporal workaround is to accept a memory leak in the cubarithm routine padcubex (...)
@todo There is a way to confuse the output routines for fitmode= 2. Take loops= 0. Then let it run once, then change the parameters and let it run a second time. Since I have no idea and this possibility is rather a relict, I leave it at that for now.
@todo Last change was to include pointsource lists. The next thing
to do is to get a generic enlargement of possible parameters. This
will not happen for a while (the reason to write thigs down
accurately). The new functions srprep() and srconst() gridpoint()
that control the generation of a model already contain the
parameter mode (which might be deleted, because there is a better
variant). The plan is to run a check on starting time of the
program, which calculations have to be done at runtime and control
this by the use of pointers to functions that are in the ringparms
struct. If e.g. a parameter is constant and will not be changed, a
whole section of calculation can be omitted. The simplest example
is the introduction of a vertical height of a disk. Calculations by
adding something to z in srconst can be omitted, if the user has
set this value uniformely to 0 and doesn't intend to change the
height. The idea is to include a pointer to a function in the
ringparms struct, that points to a function that either does the
calculations or that does nothing. If now srprep or srconst is
called, they will use the predefined pointers in a sensible series,
doing either a calculation or nothing.
@todo check for the necessity for a flushing of parameters in the function interpover
$Source: /Volumes/DATA_J_II/data/CVS/tirific/src/tirific_new.c,v $
$Date: 2011/05/25 22:25:26 $
$Revision: 1.26 $
$Author: jozsa $
$Log: tirific_new.c,v $
Revision 1.26 2011/05/25 22:25:26 jozsa
Left work
Revision 1.25 2011/05/11 13:37:12 jozsa
Left work
Revision 1.24 2011/05/10 00:30:16 jozsa
Left work
Revision 1.23 2011/05/04 01:51:03 jozsa
test
Revision 1.22 2011/05/04 01:08:25 jozsa
Left work
Revision 1.21 2011/05/04 01:03:41 jozsa
several changes to make genfitting possible
Revision 1.20 2011/03/23 22:32:29 jozsa
removed hdu 1 and 2, with that all storage of input parameters, left simple check whether tirific has created the file
Revision 1.19 2010/10/14 12:09:46 jozsa
Bugfix: With multiple disks, chkchange did not recognise the disk number correctly
Revision 1.18 2010/07/28 23:04:19 jozsa
Left work
Revision 1.17 2010/04/12 23:15:45 jozsa
included a few things, next is correction of coolgal
Revision 1.16 2010/04/01 09:24:19 jozsa
included and hopefully debugged: radial/vertical movement/gradients of those in z/azimuthal harmonics in velocity and surface brightness. To do 1) subclouds 2) Gaussian variations in azimuth 3) portions of a disk 4) 4 disks
Revision 1.15 2010/03/18 15:49:39 jozsa
implemented interpolation over passive parameters: indexing; implemented new syntax for parameter specification
Revision 1.14 2010/03/08 23:55:38 jozsa
left work
Revision 1.13 2010/03/02 08:23:08 jozsa
several changes, from the following versions on hdu2 is only partially checked for changes against the .def file
Revision 1.12 2009/08/04 16:28:33 jozsa
Left work
Revision 1.11 2009/05/27 15:07:38 jozsa
Left work
Revision 1.10 2008/10/10 15:42:40 jozsa
Introduced radial motion VPS1=
Revision 1.9 2008/07/30 16:22:42 jozsa
Some issue with accuracy in fillhdvarele()
Revision 1.8 2008/06/05 13:04:09 jozsa
left work
Revision 1.12 2008/02/18 16:47:23 gjozsa
graphics SDIS output
Revision 1.11 2008/02/13 16:43:47 gjozsa
silly bug
Revision 1.10 2008/01/16 11:17:24 gjozsa
bugfix concerning sdis
Revision 1.9 2008/01/09 17:50:50 gjozsa
minor bug
Revision 1.8 2008/01/09 17:25:52 gjozsa
introduced ring-dependent dispersion without performance loss
Revision 1.7 2007/08/23 15:23:26 gjozsa
Left work
Revision 1.5 2007/08/16 15:12:05 gjozsa
Left work
Revision 1.4 2007/08/15 16:28:23 gjozsa
Left work
Revision 1.3 2007/08/14 17:09:58 gjozsa
Left work
Revision 1.2 2007/07/25 17:17:09 gjozsa
Left work
Revision 1.1 2007/07/05 16:16:24 gjozsa
added to cvs control
Revision 1.66 2007/03/23 17:21:09 gjozsa
Changed back the changes from rev. 1.64, instead corrected the gridding: If the velocity increases with channel number, the pa changes by 180 deg w.r.t version pre-1.64, otherways it stays. For post-1.64 one has to change the pa by changing its signum and adding or subtracting 180 deg.
Revision 1.65 2007/02/23 10:28:10 gjozsa
BUGFIX in tirout: Works now for TIRACC > 6. Enlargened accuracy in textlog.
Revision 1.64 2007/01/17 15:54:52 gjozsa
Changed coordinate system in srconst by mirroring pp[0] to get a right hand coordinate system. In order not to change the pa definition changed the conversion functions interntoglob globtointern etc. Also did some changes to the graphics functions of which I don't know the effect. One can spot the changes via searching for 180.0 and DEGTORAD in the source
Revision 1.63 2006/12/11 12:42:07 gjozsa
BUGFIX: removed reading beam from header: too much confusion
Revision 1.62 2006/11/22 14:16:21 gjozsa
Bugfix concerning RASH and horizontal/vertical lines
Revision 1.61 2006/11/10 15:53:10 gjozsa
minor bugfix
Revision 1.60 2006/11/09 14:42:55 gjozsa
minor change
Revision 1.59 2006/11/08 14:05:03 gjozsa
included line drawing with keywords GR_VERL_i GR_HORL_i GR_VLVA_i GR_HLVA_i GR_VLCA_i GR_HLCA_i
Revision 1.58 2006/11/03 12:08:59 gjozsa
Small bugfix
Revision 1.57 2006/11/03 10:57:38 gjozsa
Introduced logarithmic scaling keywords: GR_XLOG, GR_YLOG_i, introduced hms dms for xpos and ypos in graphics output, introduced keywords RFREQ (restfrequency in Hertz) and ITOU (conversion factor from intensity in Jy/squarearcsec in u/squarecentimeter), changed DOUBLE_ACCURACY to 3E-15 to account for near zero events
Revision 1.56 2006/07/18 09:33:02 gjozsa
Left work
Revision 1.55 2006/04/11 11:46:00 gjozsa
Removed the positive SBR restriction in input
Revision 1.54 2006/04/06 10:40:25 gjozsa
Bugfix: Call of engalmod_chflgs() after changing the input cube after chisquare initialisation
Revision 1.53 2006/04/03 11:47:57 gjozsa
Left work
Revision 1.52 2005/10/12 14:50:59 gjozsa
Not really a Bugfix: Corrected the calculation of the ring normal vector
Revision 1.51 2005/10/12 09:53:45 gjozsa
Included Brigg's plots
Revision 1.50 2005/09/29 17:46:00 gjozsa
BUGFIX in the golden_section() function: refreshing pointsource lists is a crucial point
Revision 1.49 2005/08/25 10:15:05 gjozsa
Slight bug in the plot routines
Revision 1.48 2005/08/18 13:06:52 gjozsa
Left work
Revision 1.47 2005/08/15 13:15:03 gjozsa
BUGFIX: At 12523, not copying to the par array will result in funny results, when the only output is a .def file. Don't know whether this will cause sequals
Revision 1.45 2005/07/27 14:27:34 gjozsa
Again improved the graphics output
Revision 1.44 2005/07/27 14:01:30 gjozsa
Improved the graphics output
Revision 1.43 2005/06/28 13:28:08 gjozsa
Changed the out of range behaviour in golden_section()
Revision 1.42 2005/06/24 16:44:51 gjozsa
added interpolation possibility for the TIRDEF= output, not yet for TIRSMOOTH=
Revision 1.41 2005/06/24 12:00:30 gjozsa
Left work
Revision 1.43 2005/06/17 14:56:45 gjozsa
Bugfix
Revision 1.42 2005/06/17 14:50:45 gjozsa
Bugfix
Revision 1.41 2005/06/17 14:23:48 gjozsa
Added penalty for outliers
Revision 1.40 2005/06/13 10:40:29 gjozsa
Added possibility just to examine results
Revision 1.39 2005/06/09 14:07:45 gjozsa
Left work
Revision 1.38 2005/06/09 08:22:58 gjozsa
BUGFIX: Multiple Parameter fitting was not working properly, fixed that
Revision 1.37 2005/05/25 15:47:39 gjozsa
Added inclinogram output
Revision 1.36 2005/05/24 15:59:08 gjozsa
Added LON and LMV to table output
Revision 1.34 2005/05/24 10:42:03 gjozsa
Included graphics
Revision 1.33 2005/05/03 12:42:18 gjozsa
Left work
Revision 1.32 2005/04/28 12:44:44 gjozsa
bugfix
Revision 1.31 2005/04/28 10:13:47 gjozsa
Full introduction of pointsource lists
Revision 1.28 2005/04/26 11:44:53 gjozsa
Seems to work
Revision 1.25 2005/04/20 14:33:39 gjozsa
bug
Revision 1.24 2005/04/20 13:26:25 gjozsa
Left work
Revision 1.23 2005/04/19 13:58:50 gjozsa
Left work
Revision 1.22 2005/04/19 15:29:28 gjozsa
Finished the output functions
Revision 1.21 2005/04/19 10:59:13 gjozsa
Extended the possibilities for the histogram output
Revision 1.19 2005/04/19 07:44:43 gjozsa
Left work
Revision 1.18 2005/04/18 15:53:40 gjozsa
Added histogram functions
Revision 1.17 2005/04/18 15:02:02 gjozsa
Included TIR functions
Revision 1.16 2005/04/15 15:52:09 gjozsa
Left work
Revision 1.15 2005/04/15 15:39:13 gjozsa
Bugfix: in fct get_ringparms, documented as BUGFIX , in fct decodestring, also reported
Revision 1.14 2005/04/14 14:26:05 gjozsa
Left work
Revision 1.13 2005/04/14 10:32:16 gjozsa
Left work
Revision 1.10 2005/04/12 14:54:33 gjozsa
Changed the character of PARMAX= and PARMIN=
Revision 1.9 2005/04/11 14:23:37 gjozsa
Left work
Revision 1.8 2005/04/08 15:30:40 gjozsa
Taking into account the whole cube now, no counting for the user
Revision 1.7 2005/04/08 07:27:44 gjozsa
Bugfixes
Revision 1.6 2005/04/08 07:25:59 gjozsa
Bugfixes
Revision 1.5 2005/04/07 15:15:16 gjozsa
Bugfix in galmod(): subring velocity was overwritten by a radius, I hacked a bit, not nic at the moment
Revision 1.3 2005/04/06 15:46:25 gjozsa
Bugfixes, included monitoring of golden_section
Revision 1.2 2005/04/05 16:06:06 gjozsa
Left work
Revision 1.1 2005/04/05 11:07:37 gjozsa
The former tiridev, officially release 1
Revision 1.41 2005/04/04 08:42:09 gjozsa
removed bug
Revision 1.40 2005/04/01 15:31:54 gjozsa
Introduced writecubup and a lot of debugging, check whether the output is not too large
Revision 1.39 2005/03/29 15:56:24 gjozsa
left work
Revision 1.36 2005/03/25 18:17:20 gjozsa
Left work
Revision 1.35 2005/03/23 17:48:49 gjozsa
Implemented hdu_3 support, seems to work
Revision 1.32 2005/03/23 13:44:33 gjozsa
Implemented and tested 2nd hdu i/o
Revision 1.31 2005/03/22 17:48:07 gjozsa
Left work
Revision 1.30 2005/03/21 18:54:17 gjozsa
Left work
Revision 1.29 2005/03/19 17:55:52 gjozsa
Left work
Revision 1.26 2005/03/17 18:00:50 gjozsa
Left work
Revision 1.25 2005/03/16 17:52:00 gjozsa
Left work
Revision 1.23 2005/03/15 18:53:08 gjozsa
Left work
Revision 1.22 2005/03/15 17:28:59 gjozsa
Last changes to get a clear program structure, not ideal, but ok. Some debugging, deleting the fortran thingies
Revision 1.21 2005/03/12 16:48:33 gjozsa
Removed all clutter from readringparms and associated structs
Revision 1.19 2005/03/12 13:24:49 gjozsa
Removed all clutter from hdrinit
Revision 1.17 2005/03/12 11:37:46 gjozsa
Rearranged completely galmod, debugged and tested version of new galmod, including convolution routines, changed position angle to angle with respect to minor
Revision 1.16 2005/03/11 17:45:55 gjozsa
Left work
Revision 1.15 2005/03/10 17:56:39 gjozsa
Left work
Revision 1.13 2005/03/08 17:55:07 gjozsa
Left work
Revision 1.12 2005/03/05 17:56:09 gjozsa
Left work
Revision 1.11 2005/03/04 18:13:53 gjozsa
Left work
Revision 1.10 2005/03/03 18:00:49 gjozsa
Left work
Revision 1.9 2005/03/02 17:56:09 gjozsa
Left work
Revision 1.8 2005/03/01 17:46:21 gjozsa
Left work
Revision 1.6 2005/02/25 18:13:08 gjozsa
Left work
Revision 1.5 2005/02/25 13:34:29 gjozsa
cube io finished
Revision 1.4 2005/02/25 11:38:27 gjozsa
Created a header struct
Revision 1.3 2005/02/24 17:48:46 gjozsa
Left work
*/
/* ------------------------------------------------------------ */
/*
tirific.dc1
Program: TIRIFIC (Version 2.3.11)
Purpose: Fit a tilted-ring model to a datacube
Category: FITTING
File: tirific.c
Authors: Gyula Jozsa
Franz Kenn
Tom Oosterloo
Uli Klein
Tirific is a routine that fits a simple tilted-ring model to a
datacube INSET=. In this description we try to show all aspects of its
functionality, starting with a description how the program generates a
model datacube, how the goodness-of-fit is calculated, and what
possibilities exist to reach a "best-fit" model.
------------ !!!!NOTE!!!! ------------
Tirific is still under construction and in a test phase and does not
yet implement all functionality that will be reached with time
moving. There are many betterments that are already on our todo list,
ranging from speed improvements to a completely different
user-interface. The tirific source is held extremely flexible, such
that any user can hack easily hack away, but in any case, we are open
for any suggestion (and one will of course be to introduce a
radius-dependent velocity dispersion) and wishes and especially, we
are happy about any bug report. For receiving update reports, critics,
wishes, bug reports, send a mail to:
jozsa@astron.nl
*/
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* EXTERNAL INCLUDES */
/* ------------------------------------------------------------ */
#include <stdio.h>
#include <string.h>
#include <float.h>
#include <limits.h>
#include <sys/stat.h>
#include <gft.h>
#include <gsl/gsl_interp.h>
#include <gsl/gsl_spline.h>
#ifdef OPENMPTIR
#include <omp.h>
#endif
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* INTERNAL INCLUDES */
/* ------------------------------------------------------------ */
/* This is generated by the makefile and contains the gipsy header
files. I found no other than this disgusting way. If this module is
being changed, the makefile has to be changed accordingly. I found
no way around this */
/* #include "gipsylinc.c" */
#include <engalmod.h>
#include <maths.h>
#include <ftstab.h>
/* #include <ftsoutput.h> */
/* #include <gridnconvol.h> */
#include <cubarithm.h>
#include <pgp.h>
#include <simparse.h>
#include <fourat.h>
#include "opsystems.h"
#include <tirific_identifyers.h>
#include <tirific_defaults.h>
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@def _MEMORY_HERE_ON
@brief Controls the use of the memory_here module
If you don't want to use the memory_here facility comment this
define, otherways it will be included.
*/
/* ------------------------------------------------------------ */
/* #define _MEMORY_HERE_ON */
/* #include <memory_here.h> */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* PRIVATE SYMBOLIC CONSTANTS */
/* ------------------------------------------------------------ */
#define MAXNUR 128
#define MAXNAX 5
#define MAXNSUBS 2048
#define MAXVARY MAXNUR*9+1
/* Primary beam correction, since I am not sure at all if this should end up in the final code ... */
/* #define PBCORR 1 */
#ifdef PBCORR
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define PBNTELS
@brief Number of telescopes for which primary beam correction can be done
*/
/* ------------------------------------------------------------ */
#define PBNTELS 2
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define PBWSRT
@brief Number of the WSRT for primary beam correction
*/
/* ------------------------------------------------------------ */
#define PBWSRT 1
#define PBWSRT_2 2
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define PBWSRTCONST_1
@brief Constant used for WSRT primary beam correction
60.7492*pi/180/3600
*/
/* ------------------------------------------------------------ */
#define PBWSRTCONST_1 0.2945204323623329E-03
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define PBWSRTCONST_2
@brief Constant used for WSRT primary beam correction
68*pi/180/3600
*/
/* ------------------------------------------------------------ */
#define PBWSRTCONST_2 0.3296733193565160E-03
/* primary beam correction end */
#endif
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define FLOAT_ACCURACY
@brief Tolerance for floats
*/
/* ------------------------------------------------------------ */
#define FLOAT_ACCURACY 1.0E-7
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define DOUBLE_ACCURACY
@brief Tolerance for floats
*/
/* ------------------------------------------------------------ */
#define DOUBLE_ACCURACY 4.0E-14
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define VARYSTRELES
@brief Number of words in the varystr table in function readfit()
*/
/* ------------------------------------------------------------ */
#define VARYSTRELES 3000
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define VARYHSTRELES
@brief Length of the varyhstr in function readfit()
*/
/* ------------------------------------------------------------ */
#define VARYHSTRELES 3000
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define MAXVERHOLINES
@brief maximum of vertical and horizontal lines in graphout
*/
/* ------------------------------------------------------------ */
#define MAXVERHOLINES 10
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define NDISKS
@brief Number of disks, given at compile time
*/
/* ------------------------------------------------------------ */
/* #define ndisks 2 */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define RA2AS
@brief Conversion factor from rad to arcsec
*/
/* ------------------------------------------------------------ */
#define RA2AS 206264.8062470964
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define DEGTORAD
@brief Conversion factor from deg to rad
*/
/* ------------------------------------------------------------ */
#define DEGTORAD 0.0174532925199433
#define RADTODEG 57.29577951308232
#define ARCSECTODEG 0.00027777777777777777778
#define DEGTOARCSEC 3600.
#define TWOPI 6.283185307179586
#define SQRTOFTWOPI 2.5066282746310005
#define PIHALF 1.570796326794897
#define SQRTOFPIHALF 0.886226925452758
#define HPBWTOSIGMATOFORTH 0.03252139032821276
#define SPEEDOFLIGHT 2.99792458E5
#define HIRESFREQ 1.420405751786E9
#define HICONVERSION 1.248683E24
#define UTOSOLAR 8.01325e-21
#define CONVTHREEDBEAM 2.412273945579840982
#define HUGE_DBL (DBL_MAX/100.)
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define BMAJ_PRIMPOS @brief Position of the value for BMAJ in the
first description table, in case that it's not in the first header,
identifyer for primpos_numtype()
*/
/* ------------------------------------------------------------ */
#define BMAJ_PRIMPOS 1
#define BMIN_PRIMPOS 2
#define BPA_PRIMPOS 3
#define RMS_PRIMPOS 4
#define NUR_PRIMPOS 5
#define RADSEP_PRIMPOS 6
#define WEIGHT_PRIMPOS 7
#define MODE_PRIMPOS 8
#define ISEED_PRIMPOS 9
#define LOOPS_PRIMPOS 10
#define NCORES_PRIMPOS 11
#define ISEED_2_PRIMPOS 12
#define ANSTART_PRIMPOS 13
#define ANEND_PRIMPOS 14
#define ANSTEPS_PRIMPOS 15
#define INIMODE_PRIMPOS 16
#define FITMODE_PRIMPOS 17
#define OUTCUBUP_PRIMPOS 18
#define DISTANCE_PRIMPOS 19
#define PENALTY_PRIMPOS 20
#define RFREQ_PRIMPOS 21
#define ITOU_PRIMPOS 22
#define MAXITER_PRIMPOS 23
#define CALLITE_PRIMPOS 24
#define SIZE_PRIMPOS 25
#define PSSE_PRIMPOS 26 /* PSWARM seed */
#define PSNP_PRIMPOS 27 /* PSWARM number of particles */
#define PSCO_PRIMPOS 28 /* PSWARM cognition parameter */
#define PSSO_PRIMPOS 29 /* PSWARM social parameter */
#define PSMV_PRIMPOS 30 /* PSWARM maximum velocity */
#define PSNF_PRIMPOS 31 /* PSWARM number of function evaluations to go from initial weight to final weight */
#define PSII_PRIMPOS 32 /* PSWARM initial weight */
#define PSFI_PRIMPOS 33 /* PSWARM final weight */
#define PSID_PRIMPOS 34 /* PSWARM increase delta */
#define PSDD_PRIMPOS 35 /* PSWARM decrease delta */
#define INTY_PRIMPOS 36 /* interpolation type */
#define INDINTY_PRIMPOS 37 /* interpolation type */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define LASTSING_PRIMPOS
@brief Last entry in primpos not counted by disk
*/
/* ------------------------------------------------------------ */
#define LASTSING_PRIMPOS 37
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define #define LTYPE_MDPRIMPOS
@brief Last entry in primpos not counted by disk
*/
/* ------------------------------------------------------------ */
#define LTYPE_MDPRIMPOS 1
#define CFLUX_MDPRIMPOS 2
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define NUMB_MDPRIMPOS
@brief Number of primpos entries with multiple disks
*/
/* ------------------------------------------------------------ */
#define NUMB_MDPRIMPOS 2
/* #define cflux_primpos (SIZE_PRIMPOS+LTYPE_MDPRIMPOS*ndisks) */
/* Not in first header */
/* #define PARMAX_PRIMPOS (cflux_primpos+ndisks) */
/* #define PARMIN_PRIMPOS (cflux_primpos+ndisks+1) */
/* #define MODERATE_PRIMPOS (cflux_primpos+ndisks+2) */
/* #define DELSTART_PRIMPOS (cflux_primpos+ndisks+3) */
/* #define DELEND_PRIMPOS (cflux_primpos+ndisks+4) */
/* #define ITESTART_PRIMPOS (cflux_primpos+ndisks+5) */
/* #define ITEEND_PRIMPOS (cflux_primpos+ndisks+6) */
/* #define SATDELT_PRIMPOS (cflux_primpos+ndisks+7) */
/* #define MINDELTA_PRIMPOS (cflux_primpos+ndisks+8) */
/* #define ELEMENTS_PRIMPOS (cflux_primpos+ndisks+9) */
/* Third hdu */
/* #define CHISQ_PRIMPOS (cflux_primpos+ndisks+10) */
/* #define RCHISQ_PRIMPOS (cflux_primpos+ndisks+11) */
/* #define LOOPNR_PRIMPOS (cflux_primpos+ndisks+12) */
/* #define ACCEPT_PRIMPOS (cflux_primpos+ndisks+13) */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define PRIMHDN_SINGLE
@brief Number of first singular values in the first header
*/
/* ------------------------------------------------------------ */
/* #define PRIMHDN_SINGLE (LASTSING_PRIMPOS+NUMB_MDPRIMPOS*ndisks) */
/* #define PRIMHDN_SINGLE (cflux_primpos+ndisks) */
/* #define PRIMHDN_SINGLE (cflux_primpos+ndisks-1) */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define PARMAX_SECPOS
@brief Position of the value for BMAJ in the first description table
*/
/* ------------------------------------------------------------ */
/* #define PARMAX_SECPOS 1 */
/* #define PARMIN_SECPOS 2 */
/* #define MODERATE_SECPOS 3 */
/* #define DELSTART_SECPOS 4 */
/* #define DELEND_SECPOS 5 */
/* #define ITESTART_SECPOS 6 */
/* #define ITEEND_SECPOS 7 */
/* #define SATDELT_SECPOS 8 */
/* #define MINDELTA_SECPOS 9 */
/* #define ELEMENTS_SECPOS 10 */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define SECHDN_MULTI
@brief Number of columns in the second header
*/
/* ------------------------------------------------------------ */
#define SECHDN_MULTI 10
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define CHISQ_TABNR
@brief Position of the variable in the outarray after the par content
*/
/* ------------------------------------------------------------ */
#define CHISQ_TABNR 1
#define RCHISQ_TABNR 2
#define LOOPNR_TABNR 3
#define ACCEPT_TABNR 4
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define OUTTABNR
@brief Number of additional entries in the outtab
*/
/* ------------------------------------------------------------ */
#define OUTTABNR 4
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define WANGLE_GRAPHNR
@brief Description of a number of a special graphics output, note that the position in array is (NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR), which is the old definition
*/
/* ------------------------------------------------------------ */
/* #define WA_GRAPHNR (NPARAMS+(ndisks-1)*NDPARAMS+1) */
/* #define DENS_GRAPHNR (NPARAMS+(ndisks-1)*NDPARAMS+2) */
/* #define WOLD_GRAPHNR (NPARAMS+(ndisks-1)*NDPARAMS+3) */
/* #define TIP_GRAPHNR (NPARAMS+(ndisks-1)*NDPARAMS+4) */
/* #define LON_GRAPHNR (NPARAMS+(ndisks-1)*NDPARAMS+5) */
/* #define RASH_GRAPHNR (NPARAMS+(ndisks-1)*NDPARAMS+6) */
/* #define DESH_GRAPHNR (NPARAMS+(ndisks-1)*NDPARAMS+7) */
#define WA_GRAPHNR 1
#define DENS_GRAPHNR 2
#define WOLD_GRAPHNR 3
#define TIP_GRAPHNR 4
#define LON_GRAPHNR 5
#define RASH_GRAPHNR 6
#define DESH_GRAPHNR 7
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define MAXGRAPHS
@brief Maximum allowed number of viewgraphs on one page
*/
/* ------------------------------------------------------------ */
#define MAXGRAPHS 20
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define GRAPHNR
@brief Number of additional entries for graphics
*/
/* ------------------------------------------------------------ */
#define GRAPHNR 5
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define GR_INTERP_NUMLINES_DEFAULT
@brief Number of interpolating lines in graphics when interpolating in a curved way (really not important)
*/
/* ------------------------------------------------------------ */
#define GR_INTERP_NUMLINES_DEFAULT 500
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define PSW_PSSE_DEF
@brief Default value for PSSE parameter for pswarm
*/
/* ------------------------------------------------------------ */
#define PSW_PSSE_DEF 42 /* PSWARM seed */
#define PSW_PSNP_DEF 42 /* PSWARM number of particles */
#define PSW_PSCO_DEF 0.5 /* PSWARM cognition parameter */
#define PSW_PSSO_DEF 0.5 /* PSWARM social parameter */
#define PSW_PSMV_DEF 0.5 /* PSWARM maximum velocity */
#define PSW_PSNF_DEF 8000 /* PSWARM number of function evaluations to go from initial weight to final weight */
#define PSW_PSII_DEF 0.9 /* PSWARM initial weight */
#define PSW_PSFI_DEF 0.4 /* PSWARM final weight */
#define PSW_PSID_DEF 2. /* PSWARM increase delta */
#define PSW_PSDD_DEF 0.5 /* PSWARM decrease delta */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define EXMAXMETRO
@brief Maximum number of allowed attempts to make a model "out of range"
The user has the possibility to give a minimum and a maximum for a
given entry in the VARYSING and VARYMULT. If one of the parameters
is changed to a value out of range, then the model will be
discarded, and a new attempt will be done. To prevent an endless
loop, the number of maximal attempts is given. chprm_metro will
return 0 in that case.
*/
/* ------------------------------------------------------------ */
#define EXMAXMETRO 100000
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define MAGNIFICNR
@brief The number with which the delta is multiplied with at most
To make the iteration method a bit more effective, for each
unsuccessful step to surround a minimum, the delta is multiplied
with a number. After several steps, the number with which the
original delta is multiplied is big. If we have repeated this enlargement
MAGNIFICNR of times we won't do it anymore.
*/
/* ------------------------------------------------------------ */
#define MAGNIFICNR 100
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define AFAC
@brief A constant needed for the golden section
omega = (3-sqrt(5))/2 0.3819660112501052
AFAC = (1-omega)/omega
BFAC = 1-omega = omega/(1-omega)
*/
/* ------------------------------------------------------------ */
#define AFAC 1.618033988749894
#define BFAC 0.6180339887498948
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@define OUTRANGEFAC
@brief Factor to multiply the chisquare by if out of range
*/
/* ------------------------------------------------------------ */
#define OUTRANGEFAC 2.0
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* PRIVATE MACROS */
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* PRIVATE STRUCTS */
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct loginf
@brief Information about logfiles
The struct contains all necessary information and the location of
structures concerning logfiles.
*/
/* ------------------------------------------------------------ */
typedef struct loginf
{
/** @brief Name of the logfile */
char *logname;
/** @brief Logfile present or not, 0 present, 1 not present */
int logpres;
/** @brief Name of the text logfile */
char *textlog;
/** @brief Name of the progress logfile Kamphuis addition*/
char *progresslog;
/** @brief Name of the output table */
char *table;
/** @brief Distance of object */
double distance;
/** @brief reference x position */
double xref;
/** @brief reference y position */
double yref;
/** @brief Stream of the text logfile */
FILE *tstream;
/** @brief An array of length nur*NPARAMS+nur*NDPARAMS+5 containing the output numbers */
double *outarray;
/** @brief An clone of outarray, supposed to contain any final values; the name is historical */
double *grid;
/** @brief An clone of outarray, supposed to contain any final errors; the name is historical */
double *radius;
/** @brief An clone of outarray */
double *regist;
/** @brief A signal for an encountered change */
int changes;
/** @brief Number of cores */
int ncores;
} loginf;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct startinf
@brief Information about the running status of the program
The struct contains all control structures connected to rerunning
tirific after a full fitting cycle. The idea is to check whether a
file with the name startname has changed its last modified time
stamp (most conveniently, the user can choose the .def file for
that. Once this is done, tirific is rerun omitting the fft
initialisation and the reading of inset and corresponding
parameters.
*/
/* ------------------------------------------------------------ */
typedef struct startinf
{
/** @brief all about text io */
simparse_scn_arel **arel;
/** @brief Name of the restart file */
char *restartname;
/** @brief Indicator if this is the first run or a consecutive one */
int firstrun;
/** @brief Indicator of the restartid */
int restartid;
/** @brief time stamp for file */
time_t timestamp;
/** @brief container for file statistics */
struct stat *filestat;
} startinf;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct hdrinf
@brief Information about a cube
The struct contains all necessary information and the location of
structures concerning a datacube that is needed by other functions
in this module than hdr_init(). It is initialised by hdr_init. As
memeory allocation has to take place as early as possible, this is
done by hdr_init(). At the stage of hdr_init(), the chisquare
evaluation will already being initialised, hence the struct
contains the pointer to the chisquare, also.
*/
/* ------------------------------------------------------------ */
typedef struct hdrinf
{
/** @brief O/I E The name of the input set */
char *inset;
/** @brief The outset name */
char *outset;
/** @brief Every outcubup loops there will be an update of the output cube */
int outcubup;
/** @brief axis numbers (obsolete) */
/* int inaxperm[MAXNAX]; */
/** @brief The reference pixels in the set */
double setcrpix[3];
/** @brief Conversion factor from grid units to userdeltunit */
double deltgridtouser[3];
/** @brief Conversion factor from grids to userglobunit */
double globgridtouser[3];
/** @brief Conversion factor from cuniti to userglobunit always [1., 1., 0.001] */
double globsettouser[3];
/** @brief The reference values in user units */
double userglobcrval[3];
/** @brief The cdelt values in user units */
double userglobcdelt[3];
/** @brief The signum of the velocity direction, this is positive if the velocity decreases with channels in the cube, since the internal velocity direction points to the observer */
float signv;
/** @brief Conversion factor from HI column density to intensity */
double jygridtouser;
/** @brief E O beam major and minor axis and beam position angle */
float bmaj, bmin, bpa;
/** @brief sigma rms in the map */
float rms;
/** @brief rest frequency */
double rfreq;
/** @brief conversion from Jy/sqarearcsecond to atoms per square centimeter */
double itou;
/** @brief E The size of the cube in axis 1 */
int bsize1;
/** @brief E The size of the cube in axis 1 */
int bcsize1;
/** @brief E The size of the cube in axis 2 */
int bsize2;
/** @brief The total number of pixels in one plane plus padding */
int nprof;
/** @brief E Number of subsets, that is the number of planes read */
int nsubs;
/** @brief So-called coordinate words describing axes (obsolete) */
/* int *cwlo; */
/** @brief So-called coordinate words describing axes (obsolete) */
/* int *cwhi; */
/** @brief Coordinate description (coordinate words) of the subsets (planes) (obsolete) */
/* int *insubs; */
/** The input cube, full struct (done) */
Cube *oric;
/** The output cube, full struct (done) */
Cube *modelc;
/** The cool cube */
Cube *coolcube;
/** Half the size in z of the cool cube */
float coolhalfc;
/** nprof of the cool cube */
int nprofcool;
/** nprof of the cool cube */
int coolbin;
/** @brief The cube himself, pixels only (done) */
/* float *ori; */
/** @brief The model, pixels only (done) */
/* float *model; */
/** @brief The chisquare */
double chi2;
/** @brief An old chisquare */
double oldchi2;
#ifdef PBCORR
/** @brief Primary beam */
float *primbeam;
#endif
} hdrinf;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct varlel
@brief Element of a linked list, describing the change of the model
varlel is an element of a linked list that describes the change of
the model. Each element contains a list of numbers (int) that are
the component numbers of the parameter in the par array of the
ringparms struct, the number of adressed elements, and a delta
which controls the variation of the parameters at a time.
*/
/* ------------------------------------------------------------ */
typedef struct varlel
{
/** @brief The number of elements */
int nelem;
/** @brief numbers of the elements in the varlist */
int *elements;
/** @brief The parameter maximum */
double parmax;
/** @brief The parameter minimum */
double parmin;
/** @brief moderating steps */
int moderate;
/** @brief The starting delta */
double delstart;
/** @brief The end delta */
double delend;
/** @brief The starting number of iterations */
double itestart;
/** @brief The ending number of iterations */
double iteend;
/** @brief The delta for the satisfaction */
double satdelt;
/** @brief Delta to stop the iteration process */
double mindelta;
/** @brief Indicator for a change in genfit: 0 not changed, 1: change */
int indicator;
/** @brief The next element */
struct varlel *next;
} varlel;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct srd
@brief Sub-ring-descriptor
Contains a preprocessed description of a subring, such as
floating-point pre-calculations. Is touched by function srinit(),
*/
/* ------------------------------------------------------------ */
typedef struct srd
{
/** @brief Sin of the inclination */
float sini;
/** @brief Cos of inclination */
float cosi;
/** @brief Sin of position angle */
float sinp;
/** @brief Cos of position angle */
float cosp;
/** @brief Sin velocity, 1st order */
float vps1;
/** @brief Cos velocity, 1st order */
float vpc1;
/** @brief Sin velocity, 2nd order */
float vps2;
/** @brief Cos velocity, 2nd order */
float vpc2;
/** @brief Sin velocity, 3rd order */
float vps3;
/** @brief Cos velocity, 3rd order */
float vpc3;
/** @brief Sin velocity, 4th order */
float vps4;
/** @brief Cos velocity, 4th order */
float vpc4;
/** @brief Sin velocity, 1st order */
float ras1;
/** @brief Cos velocity, 1st order */
float rac1;
/** @brief Sin velocity, 2nd order */
float ras2;
/** @brief Cos velocity, 2nd order */
float rac2;
/** @brief Sin velocity, 3rd order */
float ras3;
/** @brief Cos velocity, 3rd order */
float rac3;
/** @brief Sin velocity, 4th order */
float ras4;
/** @brief Cos velocity, 4th order */
float rac4;
/** @brief Sin velocity, 1st order */
float ros1;
/** @brief Cos velocity, 1st order */
float roc1;
/** @brief Sin velocity, 2nd order */
float ros2;
/** @brief Cos velocity, 2nd order */
float roc2;
/** @brief Sin velocity, 3rd order */
float ros3;
/** @brief Cos velocity, 3rd order */
float roc3;
/** @brief Sin velocity, 4th order */
float ros4;
/** @brief Cos velocity, 4th order */
float roc4;
/** @brief Sin warp, 1st order */
float wps1;
/** @brief Cos warp, 1st order */
float wpc1;
/** @brief Sin warp, 2nd order */
float wps2;
/** @brief Cos warp, 2nd order */
float wpc2;
/** @brief Sin warp, 3rd order */
float wps3;
/** @brief Cos warp, 3rd order */
float wpc3;
/** @brief Sin warp, 4th order */
float wps4;
/** @brief Cos warp, 4th order */
float wpc4;
/** @brief Inverse of the sum of absolute surface brightnesses, all modes */
float sbrmax;
/** @brief NORMALISED surface brightness, 0th order */
float spb0;
float sps1;
float spc1;
float sps2;
float spc2;
float sps3;
float spc3;
float sps4;
float spc4;
/** @brief Gaussian dispersion in radians */
float gaudi[4];
/** @brief allowed ranges in radians */
float ranges[2][4];
/** @brief indicator if out of range */
int outofrange;
/** @brief Number of pointsources */
long n;
/** @brief Number of pointsources from normal/harmonics calculation*/
long nharmnorm;
/** @brief Number of pointsources from Gaussian calculation */
long ngaussian[4];
/** @brief Number of pointsources with positive flux */
long npos;
/** @brief Number of pointsources with negative flux */
long nneg;
/** @brief Number of pointsources outside the cube */
long outn;
/** @brief Number of negative pointsources outside the cube */
/* long outnpos; */
/** @brief Number of positive pointsources outside the cube */
/* long outnneg; */
#ifdef PBCORR
/** @brief method to grid the point sources */
void (*gridpoint)(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
/** @brief method to put the point sources onto the cube */
int (*srput)(void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long grid), struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk);
#else
/** @brief method to grid the point sources */
void (*gridpoint)(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
/** @brief method to put the point sources onto the cube */
int (*srput)(struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk);
#endif
/** @brief Flux of one pointsource */
float pf;
/** @brief Pointsource list, an array of pointers to points in the cube */
float **pl;
#ifdef PBCORR
/** @brief primary beam factor list, an array of floats, used for primary beam correction */
float *pbfac;
#endif
/** @brief length of pointsource list */
long pllength;
/** @brief Number of subclouds */
int nsubcl;
/** @brief Number of outliers (for parallel bookkeeping) */
long outpoints;
/** @brief Number of clouds equivalent to flux (positive minus negative, for parallel bookkeeping) */
int allnpoints;
/** @brief Number of clouds equivalent to flux (positive minus negative, for parallel bookkeeping) */
long fluxpoints;
/** @brief Number of subclouds, inverted */
float nsubclinv;
/** @brief The seed for random number generator (from ringparms) */
int iseed2[2];
/** @brief The seed for random number generator (from inf_smi) */
int iseed[2];
/** @brief The seed for random number generator (from inf_sdis) */
int siseed[2];
/** @brief The allocated permanent random generator (from inf_smi) */
maths_rstrf *randstr;
/** @brief The allocated permanent random generator (from inf_sdis) */
maths_rstrf *srandstr;
/** @brief The allocated permanent random generator (from ringparms) */
maths_rstrf *permrandstr;
/** @brief The allocated permanent random generator (from inf_gau) */
maths_rstrf *grandstr[4];
/** @brief Number saved for zprof */
float y2;
} srd;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inlistel
@brief A linked list of integers
*/
/* ------------------------------------------------------------ */
typedef struct inlistel
{
int i;
struct inlistel *next;
} inlistel;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_smi
@brief struct to handle the harmonic terms in surface brightness
*/
/* ------------------------------------------------------------ */
typedef struct inf_smi {
/** @brief The seed for random number generator */
/* parallel changed this */ /* int iseed[2]; */
/** @brief function initialising the rng */
void (*rndmf_init)(void *rpm, int srnr, int disk);
/** @brief The allocated permanent random generator */
/* parallel changed this */ /* maths_rstrf *randstr; */
/** @brief The function to prepare the subring variable sbrmax */
void (*srprsbrmax)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, term zeroth order */
void (*srprb0)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, sin term first order */
void (*srprs1)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, cos term first order */
void (*srprc1)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, sin term second order */
void (*srprs2)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, cos term second order */
void (*srprc2)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, sin term third order */
void (*srprs3)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, cos term third order */
void (*srprc3)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, sin term fourth order */
void (*srprs4)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables, cos term fourth order */
void (*srprc4)(void *rpm, int srnr, int disk);
/** @brief The function to add the zeroth order term, sin component */
void (*prb0)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the first order term, sin component */
void (*prs1)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the first order term, cos component */
void (*prc1)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the second order term, sin component */
void (*prs2)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the second order term, cos component */
void (*prc2)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the third order term, sin component */
void (*prs3)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the third order term, cos component */
void (*prc3)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the fourh order term, sin component */
void (*prs4)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to add the fourth order term, cos component */
void (*prc4)(void *rpm, float *flux, int srnr, float sinaz, float cosaz, int disk);
/** @brief Function to determine the cloud number */
void (*getcloudnumber) (void *rpm, int srnr, int disk);
/** @brief Function returning azimuth and flux signum of new point source */
void (*getaz)(void* rpm, float *az, float *cosaz, float *sinaz, int *signum, int srnr, int disk);
} inf_smi;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_gau
@brief struct to handle the Gaussian terms in surface brightness
*/
/* ------------------------------------------------------------ */
typedef struct inf_gau {
void (*srpr0) (void *rpm, int srnr, int i, int disk);
void (*srpr1) (void *rpm, int srnr, int i, int disk);
void (*srpr2) (void *rpm, int srnr, int i, int disk);
void (*srpr3) (void *rpm, int srnr, int i, int disk);
/** @brief function initialising the rng, nth Gaussian */
void (*rndmf_init0)(void *rpm, int srnr, int i, int disk);
void (*rndmf_init1)(void *rpm, int srnr, int i, int disk);
void (*rndmf_init2)(void *rpm, int srnr, int i, int disk);
void (*rndmf_init3)(void *rpm, int srnr, int i, int disk);
/** @brief The allocated random generators */
/* parallel changed this */ /* maths_rstrf *randstr[4]; */
/** @brief Function to determine the cloud number */
void (*getcloudnumber0) (void *rpm, int srnr, int i, int disk);
void (*getcloudnumber1) (void *rpm, int srnr, int i, int disk);
void (*getcloudnumber2) (void *rpm, int srnr, int i, int disk);
void (*getcloudnumber3) (void *rpm, int srnr, int i, int disk);
} inf_gau;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_sdis
@brief struct to handle the ring dependent dispersion
*/
/* ------------------------------------------------------------ */
typedef struct inf_sdis {
/** @brief The seed for the velocity dispersional random number generator */
/* parallel changed this */ /* int iseed[2]; */
/** @brief The allocated permanent random generator */
/* parallel changed this */ /* maths_rstrf *randstr; */
/** @brief function initialising the dispersion rng */
void (*rndmf_init)(void *rpm, int srnr, int disk);
/** @brief The function to calculate the ring-dependent dispersion */
void (*pr)(void *rpm, float *v, float *vold, int srnr, int disk);
/** @brief The function to forward the rng */
void (*pr_empty)(void *rpm, int srnr, int disk);
/** @brief The function to calculate and grid the ring-dependent dispersion over and over again */
void (*repeater)(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk);
/** @brief The function to change the numbers of cloud flux and cloud number */
void (*chclfl)(void *rpm, int srnr, int disk);
} inf_sdis;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_azi
@brief struct to handle the ring dependent dispersion
*/
/* ------------------------------------------------------------ */
typedef struct inf_azi {
/** @brief Preparing the ranges from the parameters and other things */
void (*srpr0) (void *rpm, int srnr, int i, int disk);
void (*srpr1) (void *rpm, int srnr, int i, int disk);
/** @brief The function to check if a point source is accepted */
void (*setoutrange)(int *outofrange);
/** @brief The function to check if a point source is accepted */
void (*pr0)(float *azi, float ranges[2][4], int *outofrange, int i);
void (*pr1)(float *azi, float ranges[2][4], int *outofrange, int i);
/** @brief The function to shape the point source */
int (*srshape)(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk);
/** @brief Function correcting for the point source number */
void (*corrp)(void *rpm, int srnr, int *outofrange, int signum);
} inf_azi;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_vrad
@brief struct to handle the vertical gradient in rotation velocity
*/
/* ------------------------------------------------------------ */
typedef struct inf_vrad {
/** @brief The function to calculate the radial term */
void (*pr)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
} inf_vrad;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_vver
@brief struct to handle the vertical gradient in rotation velocity
*/
/* ------------------------------------------------------------ */
typedef struct inf_vver {
/** @brief The function to calculate the radial term */
void (*pr)(void *rpm, float *v, int srnr, int disk);
void (*pr_rota)(void *rpm, float *v, float *v2, int srnr, int disk);
} inf_vver;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_dvro
@brief struct to handle the vertical gradient in rotation velocity
*/
/* ------------------------------------------------------------ */
typedef struct inf_dvro {
/** @brief The function to calculate the radial term */
void (*pr)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
} inf_dvro;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_dvra
@brief struct to handle the vertical gradient in rotation velocity
*/
/* ------------------------------------------------------------ */
typedef struct inf_dvra {
/** @brief The function to calculate the radial term */
void (*pr)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
} inf_dvra;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_dvve
@brief struct to handle the vertical gradient in rotation velocity
*/
/* ------------------------------------------------------------ */
typedef struct inf_dvve {
/** @brief The function to calculate the radial term */
void (*pr)(void *rpm, float *point, int srnr, int disk);
} inf_dvve;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_vm0
@brief struct to handle the planar s1 term
*/
/* ------------------------------------------------------------ */
typedef struct inf_vm0 {
/** @brief The function to calculate the radial term */
void (*pr)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
} inf_vm0;
typedef struct inf_vm1 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_vm1;
typedef struct inf_vm2 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_vm2;
typedef struct inf_vm3 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_vm3;
typedef struct inf_vm4 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_vm4;
typedef struct inf_ro1 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ro1;
typedef struct inf_ro2 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ro2;
typedef struct inf_ro3 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ro3;
typedef struct inf_ro4 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ro4;
typedef struct inf_ra1 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ra1;
typedef struct inf_ra2 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ra2;
typedef struct inf_ra3 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ra3;
typedef struct inf_ra4 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_ra4;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@struct inf_wm0
@brief struct to handle the planar s1 term
*/
/* ------------------------------------------------------------ */
typedef struct inf_wm0 {
/** @brief The function to calculate the radial term */
void (*pr)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
} inf_wm0;
typedef struct inf_wm1 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_wm1;
typedef struct inf_wm2 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_wm2;
typedef struct inf_wm3 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_wm3;
typedef struct inf_wm4 {
/** @brief The function to calculate the radial term, sin component */
void (*prs)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to calculate the radial term, cos component */
void (*prc)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/** @brief The function to prepare the subring variables */
void (*srprs)(void *rpm, int srnr, int disk);
/** @brief The function to prepare the subring variables */
void (*srprc)(void *rpm, int srnr, int disk);
} inf_wm4;
typedef struct inf_ls0 {
/** @brief The function to calculate a shift along the major axis */
void (*pr)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
} inf_ls0;
typedef struct inf_lc0 {
/** @brief The function to calculate a shift along the major axis */
void (*pr)(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
} inf_lc0;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/*
@struct ringparms
@brief All variables that are needed for the description of the rings
@li @c float @c x x position in arcsec (grids)
*/
/* ------------------------------------------------------------ */
typedef struct ringparms
{
/** @brief Number of disks */
int ndisks;
/** @brief Number of rings */
int nur;
/** @brief Array of size nur*(NPARAMS+(ndisks-1)*NDPARAMS)+1 containing the parameters */
double *par;
/* Layer type */
int *ltype;
/** @brief Array of same size containing the previous parameters */
double *oldpar;
/** @brief Array tracking if a parameter has changed, for use in chkchange */
int *chapar;
/** @brief Subset separation in grids */
double radsep;
/** @brief number of subrings */
int nr;
/** @brief big version of par, for all subrings */
float *modpar;
/** @brief array of interpolation objects, for each parameter class one */
gsl_interp **gsl_interparray;
/** @brief array of interpolation lookup objects */
gsl_interp_accel **gsl_interp_accelarray;
/** @brief array of smoothing schemes for each parameter: 0: linear 1: spline 2: Akima */
int *smothcar;
/** @brief array of interpolation objects, for each parameter class one */
gsl_interp **gsl_indinterparray;
/** @brief array of interpolation lookup objects */
gsl_interp_accel **gsl_indinterp_accelarray;
/** @brief array of smoothing schemes for each parameter for indexing: 0: linear 1: spline 2: Akima */
int *smothindcar;
/** @brief dummy of size nur used in interpolation: array of binary values 1: active, 0: indexed */
int *actarray;
/** @brief dummy of size nur used in interpolation: array of indices of current parameter array */
int *actindar;
/** @brief dummy of size nur used in interpolation: input to interpolation function, y */
double *interar;
/** @brief dummy of size nur used in interpolation: input to interpolation function, x */
double *radar;
/** @brief Flux of one cloud */
double *cflux;
/** @brief Noise weighting */
float weight;
/** @brief Memory mode */
int mode;
/** @brief Initialisation mode */
int inimode;
/** @brief The allocated permanent random generator */
/* parallel changed this */ /* maths_rstrf *permrandstr[ndisks]; */
/** @brief One seed argument for the permanent random number generator */
/* parallel changed this */ int iseed2;
/** @brief A list of subring descriptors */
srd **sd;
/** @brief The number of pointsources outside the cube */
long outpoints;
/** @brief A dummy for use in writemodel */
int *allnpoints;
/** @brief A dummy for use in writemodel */
long *fluxpoints;
/** @brief The penalty for outlyers */
double penalty;
/** @brief The factor for penalties sigmax^2*sigmay^2/sigma_rms^2 */
double penfact;
/** @brief struct to handle the ring dispersion */
inf_sdis **inf_sdisv;
/** @brief structs to handle radial, vertical velocities and vertical gradients */
inf_vrad **inf_vradv;
inf_vver **inf_vverv;
inf_dvro **inf_dvrov;
inf_dvra **inf_dvrav;
inf_dvve **inf_dvvev;
/** @brief struct to handle the planar s0 term */
inf_vm0 **inf_vm0v;
inf_vm1 **inf_vm1v;
inf_vm2 **inf_vm2v;
inf_vm3 **inf_vm3v;
inf_vm4 **inf_vm4v;
/** @brief struct to handle the planar s0 term */
inf_ra1 **inf_ra1v;
inf_ra2 **inf_ra2v;
inf_ra3 **inf_ra3v;
inf_ra4 **inf_ra4v;
/** @brief struct to handle the planar s0 term */
inf_ro1 **inf_ro1v;
inf_ro2 **inf_ro2v;
inf_ro3 **inf_ro3v;
inf_ro4 **inf_ro4v;
/** @brief struct to handle the warp s0 term */
inf_wm0 **inf_wm0v;
inf_wm1 **inf_wm1v;
inf_wm2 **inf_wm2v;
inf_wm3 **inf_wm3v;
inf_wm4 **inf_wm4v;
/** @brief struct to handle the lopsidedness sin and cos term */
inf_ls0 **inf_ls0v;
inf_lc0 **inf_lc0v;
/** @brief struct to handle the surface brightness distribution */
inf_smi **inf_smiv;
/** @brief struct to handle the surface brightness distribution, Gaussian arms */
inf_gau **inf_gauv;
/** @brief struct to handle excluding ranges */
inf_azi **inf_aziv;
#ifdef PBCORR
/** @brief Function to allocate the primary beam factor list */
void (*alloc_pbcfac)(struct ringparms *rpm, int srnr, int disk);
/** @brief Function to deallocate the primary beam factor list */
void (*dealloc_pbcfac)(struct ringparms *rpm, int srnr, int disk);
/** @brief Function to fill the primary beam factor list */
void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid);
/** @brief Function to fold in the primary beam factor list when constructing the cube*/
void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long grid);
#endif
} ringparms;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/*
@struct reg_cont
@brief A container to handle regularisation
*/
/* ------------------------------------------------------------ */
typedef struct reg_cont
{
/** @brief fourat container (see fourat.h) */
fourat_container *fc;
/** @brief Correct position in the par array */
int posoffirst;
/** @brief pointer to correct position in the par array */
double *first;
/** @brief start of the step for penalising */
double regthre;
/** @brief width of the step for penalising */
double regwidt;
/* amplitude of the step for penalising */
double regampl;
/* step for amplitude per loop */
double regaste;
/* step for amplitude per loop */
double regampd;
/** @brief ratio, for storage */
double ratio;
} reg_cont;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/*
@struct fitparms
@brief All variables that are needed for the description of the fitting process
@li @c float @c x x position in arcsec (grids)
*/
/* ------------------------------------------------------------ */
typedef struct fitparms
{
/** @brief The list for variation of parameters */
varlel *varylist;
/** @brief Number of models to compute */
int loops;
/** @brief Start annealing factor */
/* double anstart; */
/** @brief Stop annealing factor */
/* double anend; */
/** @brief Annealing steps */
/* int ansteps; */
/** @brief The initialised normal random generator */
maths_rstr *normrandstr;
/** @brief Random number initialisation */
int iseed[2];
/** @brief The fitting procedure: 0: annealing, 1: golden section */
int fitmode;
/** @brief The number of the current loop minus one */
long loopnr;
/** @brief The number of models calculated, only in use for fitmode > 1 */
long recnr;
/** @brief An indicator if something is out of range */
int outofrange;
/** @brief The current number of pointsources */
int *npoints;
/** @brief The fitter */
gft_mst *gft_mstv;
/** @brief The container of additional arguments*/
void *adar;
/** @brief Total maximum iterations for gft */
int maxiter;
/** @brief Total maximum steps per iteration for gft */
int callite;
/** @brief Size of solution relative to minsteps (grid normalisation) */
double size;
/** @brief PSWARM seed */
int psse;
/** @brief PSWARM number of particles */
int psnp;
/** @brief PSWARM cognition parameter */
double psco;
/** @brief PSWARM social parameter */
double psso;
/** @brief PSWARM maximum velocity */
double psmv;
/** @brief PSWARM number of function evaluations to go from initial weight to final weight */
int psnf;
/** @brief PSWARM initial weight */
double psii;
/** @brief PSWARM final weight */
double psfi;
/** @brief PSWARM increase delta */
double psid;
/** @brief PSWARM decrease delta */
double psdd;
/** @brief The input of vary, saved for output */
char *varyhstr;
/** @brief The index and dependencies*/
decomp_inlist *index;
/** @brief Monitoring: variable to report on the number of point sources contributing to flux*/
long *fluxpoints;
/** @brief Container for regularisation */
reg_cont **reg_contv;
/** @brief Monitoring variable for use in genfit */
size_t mon_alloops;
/** @brief Monitoring variable for use in genfit */
size_t mon_niters;
/** @brief Monitoring variable for use in genfit */
size_t mon_iters;
/** @brief Monitoring variable for use in genfit */
size_t mon_alliter;
/** @brief Monitoring variable for use in genfit */
size_t mon_allcalls;
/** @brief Monitoring variable for use in genfit */
size_t mon_calls_st;
/** @brief Monitoring variable for use in genfit */
size_t mon_ncalls_st;
/** @brief Monitoring variable for use in genfit */
size_t mon_maxiter;
/** @brief Monitoring variable for use in genfit */
size_t mon_loops;
/** @brief Monitoring variable for use in genfit */
double mon_bestchisq;
/** @brief Monitoring variable for use in genfit */
double mon_actchisq;
/** @brief Monitoring variable for use in genfit */
double mon_dsize;
/** @brief Monitoring variable for use in genfit */
double *mon_dpar;
/** @brief Monitoring variable for use in genfit */
double mon_stopsize;
/** @brief Monitoring variable for use in genfit */
double mon_size;
/** @brief Monitoring variable for use in genfit */
int mon_npar_cur;
/** @brief Monitoring variable for use in genfit */
int mon_npar;
/** @brief Monitoring variable for use in genfit */
int mon_ring;
/** @brief Monitoring variable for use in genfit */
int *mon_repnpoints;
/** @brief Monitoring variable for use in genfit */
double *mon_totalflux;
/** @brief Monitoring variable for use in genfit */
char mon_key[20];
/** @brief degrees of freedom */
double dof;
} fitparms;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/*
@struct adar
@brief additional arguments to be read by the fitting function passed to gft
This is practically everything
*/
/* ------------------------------------------------------------ */
typedef struct adar
{
/** @brief The startinf struct */
startinf *startinfv;
/** @brief The loginf struct */
loginf *log;
/** @brief The hdrinf struct */
hdrinf *hdr;
/* @brief The ring parameters */
ringparms *rpm;
/* @brief The fitparms struct */
fitparms *fit;
} adar;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/*
@struct vector
@brief A threedimensional vector
@li @c float @c x x position in arcsec (grids)
*/
/* ------------------------------------------------------------ */
typedef struct vector
{
/** @brief x component */
double x;
/** @brief y component */
double y;
/** @brief z component */
double z;
} vector;
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* (PRIVATE) GLOBAL VARIABLES */
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@var errno
@brief Needed by giplib for no obvious reason
*/
/* ------------------------------------------------------------ */
int errno;
/* Check for the beam read-in and the map unit read-in if changing this, also check function makecoolhdr() (obsolete) */
/* static char userdeltunit[] = "ARCSEC"; */
/* static char user3deltunit[] = "KM/S"; */
/* static char userglobunit[] = "DEGREE"; */
/* static char user3globunit[] = "KM/S"; */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* PRIVATE TYPEDEFS */
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* PRIVATE FUNCTION DECLARATIONS */
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int create_defaults_from_dcp(hdrinf * hdr, decomp_listel *decomp_listelv, double *parmax, double *parmin, int *moderate, double *delstart, double *delend, int *itestart, int *iteend, double *satdelt, double *mindelta, int nur, int ndisks, int fitmode)
@brief Creates defaults from a decomp list
The arrays need to be allocated and will be filled with the appropriate defaults depending on the contents of decomp_listelv.
@param hdr (hdrinf *) A header descriptor struct, properly filled.
@param decomp_listelv (decomp_listel *) decomp array as returned by decomp_get() from the simparse module
@param parmax (double *) Parameter maxima
@param parmin (double *) Parameter minima
@param moderate (int *) Moderate array
@param delstart (double *) Delstart array
@param delend (double *) Delend array
@param itestart (int *) Itestart array
@param iteend (int *) Iteend array
@param satdelt (double *) Satdelt array
@param mindelta (double *) Mindelta array
@param nur (int) Number of rings
@param ndisks (int) Number of disks
@param fitmode (int) Fitmode
@return (success) int create_varylist_from_dcp: 0
(error) 1;
*/
/* ------------------------------------------------------------ */
static int create_defaults_from_dcp(hdrinf * hdr, decomp_listel *decomp_listelv, double *parmax, double *parmin, int *moderate, double *delstart, double *delend, int *itestart, int *iteend, double *satdelt, double *mindelta, int nur, int ndisks, int fitmode);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static varlel *create_varylist_from_dcp(hdrinf * hdr, decomp_listel *decomp_listelv, double *parmax, double *parmin, int *moderate, double *delstart, double *delend, int *itestart, int *iteend, double *satdelt, double *mindelta, int nur, int ndisks)
@brief Creates a varlel list from a decomp list
The arrays need to be allocated and need to contain as many elements as input groups are recorded in decomp_listelv.
@param hdr (hdrinf *) A header descriptor struct, properly filled.
@param decomp_listelv (decomp_listel *) decomp array as returned by decomp_get() from the simparse module
@param parmax (double *) Parameter maxima
@param parmin (double *) Parameter minima
@param moderate (int *) Moderate array
@param delstart (double *) Delstart array
@param delend (double *) Delend array
@param itestart (int *) Itestart array
@param iteend (int *) Iteend array
@param satdelt (double *) Satdelt array
@param mindelta (double *) Mindelta array
@param nur (int) Number of rings
@param ndisks (int) Number of disks
@return (success) varlel *create_varylist_from_dcp: NULL terminated varylist
(error) NULL;
*/
/* ------------------------------------------------------------ */
static varlel *create_varylist_from_dcp(hdrinf * hdr, decomp_listel *decomp_listelv, double *parmax, double *parmin, int *moderate, double *delstart, double *delend, int *itestart, int *iteend, double *satdelt, double *mindelta, int nur, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static char *gluetodecomp(char **inputofvarymult, char **inputofvarysing)
@brief Creates a decomp-readable list from inputofvarymult and inputofvarysing
For compatibility reasons, the VARYMULT= and VARYSING= parameters
are still allowed. This creates a string from a char ** array as
given by sparsenext that uses whitespaces to separate the input
fields from varymult and varysing to create an equivalent string
for the VARY= parameter.
@param inputofvarysing (char **) A NULL-terminated list of strings
@param inputofvarymult (char **) A NULL-terminated list of strings
@return (success) gluetodecomp (char *) allocated array
(error) NULL if memory allocation fails
*/
/* ------------------------------------------------------------ */
static char *gluetodecomp(char **inputofvarymult, char **inputofvarysing);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int writemodel(hdrinf *origin, ringparms *rpm, fitparms *fit, double *par, decomp_inlist *index);
@brief Writes the model to the output
@param origin (hdrinf *) header info struct initialised by get_hdrinf()
@param rpm (ringparms *) properly configured ringparms struct
@param fit (fitparms *) properly configured fitparms struct
@param par (double *) properly configured parameter list, the values of which get used
@param index (decomp_index *) index list as returned in simparse
@return (success) 1;
(error) 0;
*/
/* ------------------------------------------------------------ */
static int writemodel(hdrinf *origin, ringparms *rpm, fitparms *fit, double *par, decomp_inlist *index);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int anyout_tir(int *device, char *message)
@brief wrapper to call anyout_c from gipsy
For the description of the input parameters see GIPSY, char gets
converted via fchar and int gets converted via cast to fint
@param device (int *) (dummy)
@param message (char *)
TIR_ONLY
@return see anyout_c, return is casted to int, -1 on memory problems
*/
/* ------------------------------------------------------------ */
static int anyout_tir(int *device, char *message);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int anyout_cor(FILE *device, char *message)
@brief Print a message to device
The function should be preferred to anyout_tir.
@param device (FILE *) the stream
@param message (char *) the message
TIR_ONLY
@return compare anyout_c, return is casted to int, -1 on memory problems
*/
/* ------------------------------------------------------------ */
/* static int anyout_cor(FILE *device, char *message); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int error_tir(int *device, char *message)
@brief wrapper to call error_c from gipsy
For the description of the input parameters see GIPSY, here: issue a message through stderr, abort only for *device == 4
@param device (int *)
@param message (char *)
TIR_ONLY
@return see error_c, return is casted to int, -1 on memory problems
*/
/* ------------------------------------------------------------ */
static int error_tir(int *device, char *message);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int cancel_tir(simparse_scn_arel **arel, char *parname, int depth)
@brief cancelling user input
This is basically synonymous to simparse_scn_arellist.
@param simparse_scn_arellist (simparse_scn_arel **) Allocated simparse_scn_arel NULL-terminated list.
@param key (char *) Key to remove
@param depth (int) Number of simparse_scn_arellist structs to correct, starting at 0. This can be used to e.g. correct the first two structs (e.g. user input and command line, but not any input file with depth = 1) only.
TIR_ONLY.
@return see cancel_c, return is casted to int, -1 on memory problems
*/
/* ------------------------------------------------------------ */
static int cancel_tir(simparse_scn_arel **arel, char *parname, int depth);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int userint_tir(simparse_scn_arel **arel, int *anarray, int *elements, int *defaultstat, char *keyword, char *message)
@brief wrapper to call userchar_c from gipsy
Attempt to get as close to the gipsy stuff as possible.
@param arel (simparse_scn_arel **)
@param astring (int *)
@param elements (int *)
@param defaultstat (int *)
@param keyword (char *)
@param message (char *)
TIR_ONLY.
@return see userint_c, return is casted to int, -1 on memory problems
*/
/* ------------------------------------------------------------ */
static int userint_tir(simparse_scn_arel **arel, int *anarray, int *elements, int *defaultstat, char *keyword, char *message);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int userdble_tir(simparse_scn_arel **arel, double *anarray, int *elements, int *defaultstat, char *keyword, char *message)
@brief wrapper to call userchar_c from gipsy
Attempt to get as close to the gipsy stuff as possible.
@param arel (simparse_scn_arel **) Input struct.
@param astring (double *)
@param elements (int *)
@param defaultstat (int *)
@param keyword (char *)
@param message (char *)
TIR_ONLY.
@return see userint_c, return is casted to int, -1 on memory problems
*/
/* ------------------------------------------------------------ */
static int userdble_tir(simparse_scn_arel **arel, double *anarray, int *elements, int *defaultstat, char *keyword, char *message);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int userreal_tir(simparse_scn_arel **arel, float *anarray, int *elements, int *defaultstat, char *keyword, char *message)
@brief wrapper to call userreal_c from gipsy
For the description of the input parameters see GIPSY, char gets
converted via fchar
@param arel (simparse_scn_arel **) Input struct.
@param anarray (float *)
@param elements (int *)
@param defaultstat (int *)
@param keyword (char *)
@param message (char *)
TIR_ONLY.
@return see userreal_c, -1 on memory problems
*/
/* ------------------------------------------------------------ */
static int userreal_tir(simparse_scn_arel **arel, float *anarray, int *elements, int *defaultstat, char *keyword, char *message);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double gchsq_gen_start(double *vector, void *rest);
@brief function passed to gft
The function receives a vector of fit parameters from the gft
module and returns the chisquare. Used only once on initialisation of the fitter.
@param vector (double *) An array of fit parameters
@param rest (void *) concealed adar struct
@return double gchsq_gen The chisquared
*/
/* ------------------------------------------------------------ */
static double gchsq_gen_start(double *vector, void *rest);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double gchsq_gen(double *vector, void *rest);
@brief function passed to gft
The function receives a vector of fit parameters from the gft
module and returns the chisquare. rest is a concealed adar struct
that contains the necessary connections to the fit parameters. In
case of an interrupted fitting process, this routine will read the
logfile instead of producing a real fit. If the recovery of
information has finished, the function replaces itself by
gchsq_gen2, the "real" function to get the chisquare.
@param vector (double *) An array of fit parameters
@param rest (void *) concealed adar struct
@return double gchsq_gen The chisquared
*/
/* ------------------------------------------------------------ */
static double gchsq_gen(double *vector, void *rest);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double gchsq_gen2(double *vector, void *rest);
@brief function passed to gft
The function receives a vector of fit parameters from the gft
module and returns the chisquare (checking for constraints in
parameter space), producing an appropriate output to the logfile,
the textlog, the screen, and occasionally a best-fit data cube.
rest is a concealed adar struct that contains the necessary
connections to the fit parameters.
@param vector (double *) An array of fit parameters
@param rest (void *) concealed adar struct
@return double gchsq_gen The chisquared
*/
/* ------------------------------------------------------------ */
static double gchsq_gen2(double *vector, void *rest);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static loginf *create_loginf(void)
@brief Creates a loginf structure
Creates a hdrinf structure allocating and if necessary initialising
all structs and arrays.
@return (success) hdrinf create_hdrinf: Allocated and initialised
hdrinf struct\n
(error): NULL
*/
/* ------------------------------------------------------------ */
static loginf *create_loginf(void);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroy_loginf(loginf *hdr, int ndisks)
@brief Destroys a loginf structure
Destroys a loginf structure deallocating all arrays. A
non-allocated array has to be terminated (has to have a NULL value)
to get the function work properly.
@param hdr (loginf *) A loginf struct to be destroyed
@param ndisks (int) Number of disks, only used in function call hdl_init()
@return void
*/
/* ------------------------------------------------------------ */
static void destroy_loginf(loginf *hdr, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
@brief Initialisation of the program concerning logfiles
Takes over all logfile related io, returns an allocated loginf struct.
@return (success) loginf *get_loginf: A loginf struct with the acquired info
(error) NULL
*/
/* ------------------------------------------------------------ */
static loginf *get_loginf(startinf *startinfv, loginf *loginfv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static startinf *create_startinf(void)
@brief Creates a startinf structure
Creates a hdrinf structure allocating and if necessary initialising
all structs and arrays.
@return (success) startinf create_startinf: Allocated and initialised
startinf struct\n
(error): NULL
*/
/* ------------------------------------------------------------ */
static startinf *create_startinf(void);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroy_startinf(startinf *startinfv, int ndisks)
@brief Destroys a startinf structure
Destroys a startinf structure deallocating all arrays. A
non-allocated array has to be terminated (has to have a NULL value)
to get the function work properly.
@param startinfv (startinf *) A startinf struct to be destroyed
@return void
*/
/* ------------------------------------------------------------ */
static void destroy_startinf(startinf *startinfv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static startinf *get_startinf(int argc, char **argv)
@brief Initialisation of the program concerning restart information
Takes over all startfile related io, returns an allocated startinf struct. Starts command line and file io.
@param argc (int) Number of command line arguments (as argument to main)
@param argv (char *) Array of command line arguments
@return (success) startinf *get_startinf: A startinf struct with the acquired info
(error) NULL
*/
/* ------------------------------------------------------------ */
static startinf *get_startinf(int argc, char **argv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int check_restart(startinf *startinfv, hdrinf *hdr, ringparms *rpm, loginf *log)
@brief Checks switches and returns an answer whether to restart
Takes as an input a pointer to a (properly allocated) startinf
struct and returns an answer whether to restart. If restart, checks
if rpm -> par needs to be put into intern status. If NULL is passed
for rpm, then this will not be done. If rpm is not NULL, then it
needs to be properly allocated. hdr and log must be properly allocated and filled if rpm <> 0
1: The restartfile is read out, and checked for existence or the firstrun switch is set to 1.
0: If restartfile is not defined or not existent and firstrun = 0
@param startinfv (startinf *) A startinf struct to be destroyed
@param hdr (hdrinf *) A hdr descriptor struct, properly filled.
@param rpm (ringparms *) A ring parameter descriptor struct, properly filled or NULL
@param log (loginf *) A log descriptor struct, properly filled or NULL
@return (success) 1 if a restart is appropriate
(error) 0 if stopping is recommended
*/
/* ------------------------------------------------------------ */
static int check_restart(startinf *startinfv, hdrinf *hdr, ringparms *rpm, loginf *log);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void loop_restart(startinf *startinfv)
@brief Check if restartfile exists and loop until its last change time stamp has changed with respect to the value stored in startinfv, make some switches afterwards
Set the value of firstrun in startinfv to 0. Check if restartfile
has been defined in startinfv, and check if a time stamp can be
retrieved. If either one or the other fails, return (leading to a
breakout of the restart loop via function check_restart). If
successful, repeat time stamp request, until the retrieved time
stamp changes with respect to the one stored in startinfv ->
timestamp. If that occurs, update startinfv -> startfile from the
input (command line or .def file) of the parameter RESTARTNAME=.
@param startinfv (startinf *) A startinf struct
@return int loop_restart(): 0 all ok
1 malloc problems
*/
/* ------------------------------------------------------------ */
static int loop_restart(startinf *startinfv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static hdrinf *create_hdrinf()
@brief Creates a hdrinf structure
Creates a hdrinf structure allocating and if necessary initialising
all arrays
@return (success) hdrinf create_hdrinf: Allocated and initialised
hdrinf struct\n
(error): NULL
*/
/* ------------------------------------------------------------ */
static hdrinf *create_hdrinf(void);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroy_hdrinf(hdrinf *hdr)
@brief Destroys a hdrinf structure
Destroys a hdrinf structure deallocating all arrays. A
non-allocated array has to be terminated (has to have a NULL value)
to get the function work properly
@param hdr (hdrinf *) A hdrinf struct to be destroyed
@return void
*/
/* ------------------------------------------------------------ */
static void destroy_hdrinf(hdrinf *hdr);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static hdrinf *get_hdrinf(startinf *startinfv, loginf *log, hdrinf *hdrinfv)
@brief Initialisation of the program concerning info from the dataset
Takes over all dataset related io, returns an allocated hdrinf struct, with all the current rubbish.
@param log (startinf *) A start descriptor struct, properly filled.
@param log (loginf *) A log descriptor struct, properly filled.
@param log (hdrinf *) A hdr descriptor struct, properly filled.
@return (success) hdrinf *get_hdrinf: A hdrinf struct with the acquired info and rubbish
(error) NULL
*/
/* ------------------------------------------------------------ */
static hdrinf *get_hdrinf(startinf *startinfv, loginf *log, hdrinf *hdrinfv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int get_parameter_double(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, char *message, char *parname, int force)
@brief Get a double parameter from the .def file
Reads in and checks a double parameter from the .def file for consistency with the logfile.
@param startinfv (startinf *) A startinf descriptor struct, properly filled.
@param log (loginf *) A log descriptor struct, properly filled.
@param hdr (hdrinf *) A header descriptor struct, properly filled.
@param rpm (ringparms *) A ring parameter descriptor struct, properly filled.
@param message (char *) Message to display
@param parname (char *) The parameter name
@param ident (int) The parameter identification (PXXX)
@param force (int) same as def parameter from Gipsy. If 2, hidden, 4 not hidden.
@return int get_parameter_double; 0(success) 1(error)
*/
/* ------------------------------------------------------------ */
static int get_parameter_double(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, char *message, char *parname, int ident, int force);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static srd *create_srd(int n)
@brief Creates a list of subring descriptors with n elements
The pointsource lists are terminated with NULL
@param n (int) Number of subrings to allocate the list for
@return (success) srd *create_srd: Allocated and initialised
srd list\n
(error): NULL
*/
/* ------------------------------------------------------------ */
static srd *create_srd(int n);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroy_srd(srd *sd, int n)
@brief Destroys a list of subring descriptors
The pointsource lists shold be terminated with NULL if they are
deallocated
@param sd (srd *) The list to destroy
@param n (int) Number of elements of the list.
@return void
*/
/* ------------------------------------------------------------ */
static void destroy_srd(srd *sd, int n);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static ringparms *create_ringparms(int ndisks)
@brief Creates a ringparms structure
Creates a ringparms structure allocating and if necessary initialising
all arrays
@param ndisks (int) number of disks
@return (success) ringparms *create_ringparms: Allocated and initialised
hdrinf struct\n
(error): NULL
*/
/* ------------------------------------------------------------ */
static ringparms *create_ringparms(int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroy_ringparms(ringparms *hdr)
@brief Destroys a ringparms structure
Destroys a ringparms structure deallocating all arrays. A
non-allocated array has to be terminated (has to have a NULL value)
to get the function work properly
@param hdr (ringparms *) A hdrinf struct to be destroyed
@return void
*/
/* ------------------------------------------------------------ */
static void destroy_ringparms(ringparms *hdr);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static ringparms *get_ringparms(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *ringparmsv)
@brief Fill the ringparms struct from the input
Reads in properly the ringparms struct.
@param startinfv (startinf *) A start descriptor struct, properly filled.
@param hdr (hdrinf *) A header descriptor struct, properly filled.
@param log (loginf *) A log descriptor struct, properly filled.
@param ringparmsv (ringparms *) A ringparms descriptor struct, properly filled or NULL.
@return @return (success) ringparms *get_ringparms: A ringparms struct with the acquired info and rubbish
(error) NULL
*/
/* ------------------------------------------------------------ */
static ringparms *get_ringparms(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *ringparmsv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static fitparms *create_fitparms(ringparms *rpm)
@brief Creates a fitparms structure
Creates a fitparms structure allocating and if necessary initialising
all arrays
@param rpm (ringparms *) A ring parameter descriptor struct, properly filled.
@return (success) fitparms *create_fitparms: Allocated and initialised
fitparms struct\n
(error): NULL
*/
/* ------------------------------------------------------------ */
static fitparms *create_fitparms(ringparms *rpm);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroy_fitparms(fitparms *hdr)
@brief Destroys a fitparms structure
Destroys a fitparms structure deallocating all arrays. A
non-allocated array has to be terminated (has to have a NULL value)
to get the function work properly
@param hdr (fitparms *) A hdrinf struct to be destroyed
@return void
*/
/* ------------------------------------------------------------ */
static void destroy_fitparms(fitparms *hdr);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static fitparms *get_fitparms(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fitparmsv)
@brief Fill the fitparms struct from the input
Reads in properly the fitparms struct. If run a second time only reads in the required parameters.
@param startinfv (startinf *) A start descriptor struct, properly filled.
@param log (hdrinf *) A log descriptor struct, properly filled.
@param hdr (hdrinf *) A header descriptor struct, properly filled.
@param rpm (ringparms *) A ring parameter descriptor struct, properly filled.
@param fitparmsv (fitparms *) A fit descriptor struct, properly filled or NULL.
@return @return (success) fitparms *get_fitparms: A fitparms struct with the acquired info and rubbish
(error) NULL
*/
/* ------------------------------------------------------------ */
static fitparms *get_fitparms(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fitparmsv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double dparamtointern(double value, int par, hdrinf *hdr, int ndisks)
@brief conversion of some units
Converts the input as being coordinates given by the user to inernal (grid-) units. Caution!!! For the conversion of absolute map coordinates this function is not appropriate.
Use globtointern instead!
RADI 1
VROT 2
Z0 3
SBR 4
INCL 5
PA 6
XPOS 7
YPOS 8
VSYS 9
CONDISP 10
@param value (double) value to convert
@param par (char) type of parameter (see above)
@param hdr (hdrinf *) The properly configured header description struct
@param ndisks (int) Number of disks
@return double paramtointern: converted value
*/
/* ------------------------------------------------------------ */
static double dparamtointern(double value, int par, hdrinf *hdr, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double ddparamtointern(double value, int par, hdrinf *hdr, int ndisks)
@brief conversion of some units
Converts the input as being coordinates given by the user to inernal (grid-) units, used only for differential quantities (as in the fitparms)
Use globtointern instead!
RADI 1
VROT 2
Z0 3
SBR 4
INCL 5
PA 6
XPOS 7
YPOS 8
VSYS 9
CONDISP 10
@param value (double) value to convert
@param par (char) type of parameter (see above)
@param hdr (hdrinf *) The properly configured header description struct
@param ndisks (int) Number of disks
@return double ddparamtointern: converted value
*/
/* ------------------------------------------------------------ */
static double ddparamtointern(double value, int par, hdrinf *hdr, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double dinterntoparam(double value, int par, hdrinf *hdr, int ndisks)
@brief conversion of some units
Converts the input as being inernal (map-) coordinates to units as given by the user. Caution!!! For the conversion of map coordinates this function is, strictly speaking, not appropriate.
Use globtointern instead!
RADI 1
VROT 2
Z0 3
SBR 4
INCL 5
PA 6
XPOS 7
YPOS 8
VSYS 9
CONDISP 10
@param value (double) value to convert
@param par (char) type of parameter (see above)
@param hdr (hdrinf *) The properly configured header description struct
@param ndisks (int) Number of disks
@return double dinterntoparam: converted value
*/
/* ------------------------------------------------------------ */
static double dinterntoparam(double value, int par, hdrinf *hdr, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double ddinterntoparam(double value, int par, hdrinf *hdr, int ndisks)
@brief conversion of some units
Converts the input as being inernal (map-) coordinates to units as given by the user, used only for differential quantities (as in the fitparms).
RADI 1
VROT 2
Z0 3
SBR 4
INCL 5
PA 6
XPOS 7
YPOS 8
VSYS 9
CONDISP 10
@param value (double) value to convert
@param par (char) type of parameter (see above)
@param hdr (hdrinf *) The properly configured header description struct
@param ndisks (int) Number of disks
@return double ddinterntoparam: converted value
*/
/* ------------------------------------------------------------ */
static double ddinterntoparam(double value, int par, hdrinf *hdr, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double simpleinterntoglob(double value, int par, hdrinf *hdr)
@brief conversion of some units
Converts the input globals as being inernal (map-) coordinates to units as
given by the user in a simple way for the use as min and max.
RADI 1
VROT 2
Z0 3
SBR 4
INCL 5
PA 6
XPOS 7
YPOS 8
VSYS 9
CONDISP 10
@param value (double) value to convert
@param par (char) type of parameter (see above)
@param hdr (hdrinf *) The properly configured header description struct
@return double simpleinterntoglob: converted value
*/
/* ------------------------------------------------------------ */
/* static double simpleinterntoglob(double value, int par, hdrinf *hdr); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double simpleglobtointern(double value, int par, hdrinf *hdr, int ndisks)
@brief conversion of some units
Converts the input globals as being global coordinates to internal
map units as given by the user in a simplified way, for the use as min and max.
RADI 1
VROT 2
Z0 3
SBR 4
INCL 5
PA 6
XPOS 7
YPOS 8
VSYS 9
CONDISP 10
@param value (double) value to convert
@param par (char) type of parameter (see above)
@param hdr (hdrinf *) The properly configured header description struct
@param ndisks (int) Number of disks
@return double simpleglobtointern: converted value
*/
/* ------------------------------------------------------------ */
static double simpleglobtointern(double value, int par, hdrinf *hdr, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double vusertointern(double value, hdrinf *hdr)
@brief conversion of absolute velocity units
Converts the input as being absolute velocity coordinates given by the user to inernal (grid-) units.
@param value (double) value to convert
@param hdr (hdrinf *) The properly configured header description struct
@return double vusertointern: converted value
*/
/* ------------------------------------------------------------ */
/* static double vusertointern(double value, hdrinf *hdr); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double vinterntouser(double value, hdrinf *hdr)
@brief conversion of absolute velocity units
Converts the input as being absolute velocity coordinates in the internal map to units given by the user.
@param value (double) value to convert
@param hdr (hdrinf *) The properly configured header description struct
@return double vinterntouser: converted value
*/
/* ------------------------------------------------------------ */
/* static double vinterntouser(double value, hdrinf *hdr); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void globtointern(double *invalue, double *outvalue, hdrinf *hdr)
@brief conversion of map units
Converts the input as being (map-) coordinates to internal units.
@param invalue (double *) values to convert, x, y, v.
@param outvalue (double *) converted values, x, y, v.
@param hdr (hdrinf *) The properly configured header description struct
@return double dinterntoparam: converted value
*/
/* ------------------------------------------------------------ */
static void globtointern(double *invalue, double *outvalue, hdrinf *hdr);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void interntoglob(double *invalue, double *outvalue, hdrinf *hdr)
@brief conversion of map units
Converts the input as being internal units to (map-) coordinates.
@param value (double *) values to convert, x, y, v.
@param outvalue (double *) converted values, x, y, v.
@param hdr (hdrinf *) The properly configured header description struct
@return double dinterntoparam: converted value
*/
/* ------------------------------------------------------------ */
static void interntoglob(double *invalue, double *outvalue, hdrinf *hdr);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void changetointern(double *params, int nur, hdrinf *hdr, int ndisks)
@brief Change the parameter list params to internal units as if being user units
@param params (double *) parameter list, nur*(NPARAMS+(ndisks-1)*NDPARAMS)+NSPARAMS elements
@param nur (int) number of rings
@param hdr (hdrinf *) A properly configured hdrinf struct
@param ndisks (int) Number of disks
@return void
*/
/* ------------------------------------------------------------ */
static void changetointern(double *params, int nur, hdrinf *hdr, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/*
@fn static int par2int(char *par);
@brief Identification of string keywords with numbers
Identifies the input string (No whitespaces to be passed) and
returns it's identification. This is somewhat critical and
dependent on the implementation of the ftstab module, call
ftstab_hdlreset_() before using:
default par2int=0
"RADI" par2int=1
"VROT" par2int=2
"Z0" par2int=3
"SBR" par2int=4
"INCL" par2int=5
"PA" par2int=6
"XPOS" par2int=7
"YPOS" par2int=8
"VSYS" par2int=9
"CONDISP" par2int=10
@param par (char *) A string to pass to the function
@return int par2int: The identifyer as defined above.
*/
/* ------------------------------------------------------------ */
/* int ftstab_gtitln_(char *titl); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/*
@fn static void int2par(char *key, int par);
@brief Identification of numbers with string keywords
Identifies the input number and
returns it's identification keyword in a string key. This is somewhat critical and
dependent on the implementation of the ftstab module, call
ftstab_hdlreset_() before using:
"DEFAULT" par2int=0
"RADI" par2int=1
"VROT" par2int=2
"Z0" par2int=3
"SBR" par2int=4
"INCL" par2int=5
"PA" par2int=6
"XPOS" par2int=7
"YPOS" par2int=8
"VSYS" par2int=9
"CONDISP par2int=10
@param par (char *) A string to pass to the function
@return int par2int: The identifyer as defined above.
*/
/* ------------------------------------------------------------ */
/* int ftstab_putcoltitl(char *key, int coltitle); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static varlel *appendvarlel(varlel *last)
@brief Constructor of an element of the varlel list
Appends a varlel struct (terminated) to the last and returns a
pointer to the appended element
@param last (varlel *) The last varlel element (or NULL)
@return (success) varlel *appendvarlel: The new element of the list
(error) NULL
*/
/* ------------------------------------------------------------ */
static varlel *appendvarlel(varlel *last);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroyvarlel(varlel *first)
@brief Destructor of a varlel list
Destroys a varlel list from first on. The element before first will
not be terminated, while the list has to be terminated. All
elements arrays have to be dynamically allocated in case of nelem
!= 0.
@param first (varlel *) The first varlel element to destroy(or NULL)
@return void
*/
/* ------------------------------------------------------------ */
static void destroyvarlel(varlel *first);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static inlistel *appendinlistel(inlistel *last)
@brief Constructor of an element of a inlistel list
Appends a inlistel struct (terminated) to the last and returns a
pointer to the appended element
@param last (inlistel *) The last varlel element (or NULL)
@return (success) inlistel *appendinlistel: The new element of the list
(error) NULL
*/
/* ------------------------------------------------------------ */
/* static inlistel *appendinlistel(inlistel *last); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int galmod(hdrinf *hdr, ringparms *rpm, int fitmode, varlel *varele, decomp_index *index, long *fluxpoints, int *allnpoints)
@brief Core to construct a pointsource cube from a parameter list
This is the part where the things that are done with galmod are
done. It is detached from the structure that passes packages of
descriptors, because it can, in principle be used everywhere. With
the fitmode and varele, the interpolation of rings and the
calculation of pointsources will be done only, if parameters have
currently been changed. For this, the information contained in the
varlel element is used. If NULL is passed, then everything will be
calculated freshly. NULL should always be passed, if not sure
whether the parameters have been interpolated correctly in a
previous run or if interpover was used as a stand-alone or not at
all before.
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Properly allocated fitparms struct
@param varele (varlel *) Actual element that is processed in the varlel list
@param index (decomp_inlist *) An index- and dependency list as provided by simparse function decomp_get_inlist()
@param fluxpoints (long *) number of pointsources contributing to flux (in case of mixed negative and positive clouds this number is not identical to the number of point sources)
@return (success) int galmod: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int galmod(hdrinf *hdr, ringparms *rpm, int fitmode, varlel *varele, decomp_inlist *index, long *fluxpoints, int *allnpoints);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int changedependent(ringparms *rpm, double *par, decomp_inlist *index, varlel *varele, int fitmode, int *chapar)
@brief Takes the parameter list and changes the parameters on the index
Takes the parameter list and identifies parameters on the index in
decomp_inlist, then interpolates between the parameters
that the parameter on the index depends on
@param rpm (ringparms *) Ring parameter information struct
@param par (double *) Parameter list
@param index (decomp_inlist *) An index- and dependency list as provided by simparse function decomp_get_inlist()
@param chapar (int *) array of parameters that change
@return (success) int changedependent: number of indexed parameters
(error) -1
*/
/* ------------------------------------------------------------ */
static int changedependent(ringparms *rpm, double *par, decomp_inlist *index, int *chapar);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void interpover(ringparms *rpm, double radsep, int fitmode, varlel *varele)
@brief Constructs the modpar array by interpolating over the par array
Constructs the modpar array by interpolating over the parameters,
that are a content of the varlel item. If fitmode = 0, then varele
is taken as the first item in a ll, and the function will scan
through all elements of this ll, if fitmode = 1, then only the
actually passed element will be scanned. If NULL is passed as a
value of varele, then all parameters are changed or "touched" even
if they stay the same value.
@param rpm (ringparms *) Ring parameter information struct
@param radsep (double) Radius separation of subring in appropriate units
@param fitmode (int) Fit mode to check for
@param varele (varlel *) Parameter list element.
@param index (decomp_inlist *) an index list as defined in simparse
@return void
*/
/* ------------------------------------------------------------ */
static void interpover(ringparms *rpm, double radsep, int fitmode, varlel *varele, decomp_inlist *index);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void interpinit(ringparms *rpm, double radsep, int disk)
@brief Constructs the modpar array by interpolating over the par array
This is the same as interpover but without checking the varlel
list. Should always be used if the par parameter list has been
changed without consulting the varlel list.
@param rpm (ringparms *) Ring parameter information struct
@param radsep (double) Radius separation of subring in appropriate units
@param disk (int) disk number; if the disk is not fitted, 0 is returned.
@return void
*/
/* ------------------------------------------------------------ */
static void interpinit(ringparms *rpm, double radsep, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int chkchangep(varlel *varele, int fitmode, int parnr, int nur)
@brief Help function to interpover: Check if the modpar array has to be changed for a parameter
If in the previous parameter change a change of the parameter has
occured, this function will return 1, 0 otherways.
@param varele (varlel *) Actual element of the varlel list, or the
first element in case of fitmode = 0
@param fitmode (int) Fitmode 0: Metropolis, 1: Golden section
parameter information struct
@param ringnr (int) Number of ring to be checked
@param nur (int) Number of rings
@return int chkchange: 1 if change for parameter has occured, 0 if not
*/
/* ------------------------------------------------------------ */
static int chkchangep(varlel *varele, int fitmode, int parnr, int nur);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srprep(ringparms *rpm, int srnr, long mode, int disk)
@brief Preparation of a srd struct
Precalculations for the calculation of a ring.
@param rpm (ringparms *) Properly configured ringparms struct
@param srnr (int *) Number of the subring (start with 0)
@param mode (long) Dummy at the moment
@param disk (int) Disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srprep(ringparms *rpm, int srnr, long mode, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static long srconst(hdrinf *hdr, ringparms *rpm, int srnr, long mode, int disk)
@brief Generation of a pointsource list
Generates a pointsource list that is attached to the appropriate srd struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param srnr (int *) Number of the subring (start with 0)
@param mode (long) Dummy at the moment
@param disk (int) Disk number
@return long srconst: Number of pointsources outside the cube
*/
/* ------------------------------------------------------------ */
static long srconst(hdrinf *hdr, ringparms *rpm, int srnr, long mode, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int srshape(hdrinf *hdr, ringparms *rpm, float sinaz, float cosaz, int srnr, long mode, int disk)
@brief Determines the coordinates of a point source
Subroutine to srconst. After the calculation of the azimuth of a
point source, the coordinates are transformed according to the
parameters in this function.
@param rpm (ringparms *) Properly configured ringparms struct
@param pp (float *) Point source coordinates
@param sinaz (float) sine of azimuth
@param cosaz (float) cosine of azimuth
@param srnr (int *) Number of the subring (start with 0)
@param disk (int) Disk number
@return long srconst: Number of pointsources outside the cube
*/
/* ------------------------------------------------------------ */
static void srshape(ringparms *rpm, float *pp, float sinaz, float cosaz, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gridpoint_norm(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, float *primbeam, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
@brief Grids a point to a pointsource list
Grids the point point (6 phase-space coords) in a list of pointers to the cube hdr ->
model. If the point doesn't fit the cube, the pointsource number of
the subring will be redced by 1, if it fits, pnr will be increased
by one. Called by srconst.
This function changes only the n variable in the pointsource descriptor.
@param hdr (hdrinf *) Properly configured hdrinf struct
@param modpar (float *) Properly configured array of subring descriptors
@param nr (int *) Properly number of subrings
@param sd (srd **) Properly configured subring descriptor
@param srnr (int) Number of the subring (start with 0)
@param pnr (long *) Number of the pointsource (start with 0)
@param pp (float *) Number of the subring (start with 0)
@param signum (int) Indicates negative point source, dummy in this function
@param npoints (long *) Number of maximal points in specific structure
@param disk (int) Disk number
@return void
*/
/* ------------------------------------------------------------ */
#ifdef PBCORR
static void gridpoint_norm(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#else
static void gridpoint_norm(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#endif
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gridpoint_mixed(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, float *primbeam, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
@brief Grids a point to a pointsource list
Grids the point point (6 phase-space coords) in a list of pointers
to the cube hdr -> model. If the point doesn't fit the cube, the
pointsource number of the subring will be redced by 1, if it fits,
pnr will be increased by one. Called by srconst. This function
changes not only the n variable in the pointsource descriptor, but
also the nneg and npos variable. Positive clouds are gridded on the
beginning of the pl array, negative clouds at the end.
@param hdr (hdrinf *) Properly configured hdrinf struct
@param modpar (float *) Properly configured array of subring descriptors
@param nr (int *) Properly number of subrings
@param sd (srd **) Properly configured subring descriptor
@param srnr (int) Number of the subring (start with 0)
@param pnr (long *) Number of the pointsource (start with 0)
@param pp (float *) Number of the subring (start with 0)
@param signum (int) Indicates negative source, needed for this function
@param npoints (long *) Number of maximal points in specific structure
@param disk (int) Disk number
@return void
*/
/* ------------------------------------------------------------ */
#ifdef PBCORR
static void gridpoint_mixed(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#else
static void gridpoint_mixed(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#endif
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int srput_norm(void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long *pnr, long grid), struct sdr **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk)
@brief Puts a pointsource list on a cube
Puts the srnrth pointsource list in rpm on the cube by adding the
flux in the list pointwise. In case of exclusively positive or exclusively negative clouds.
@param hdr (hdrinf *) Properly configured hdrinf struct
@param sd (srd **) Properly configured subring descriptor
@param modpar (float *) Properly configured subring parameter array
@param nr (int) Number of subrings
@param cflux (double *) Cloudflux as determined in the ringparms struct
@param radsep (double) Separation of subrings in pixel
@param srnr (int) Subring number
@param disk (int) Disk number
@return void
*/
/* ------------------------------------------------------------ */
#ifdef PBCORR
static int srput_norm(void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long grid), struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk);
#else
static int srput_norm(struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk);
#endif
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int srput_mixed(void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long *pnr, long grid), struct sdr **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk)
@brief Puts a pointsource list on a cube
Puts the srnrth pointsource list in rpm on the cube by adding the
flux in the list pointwise. In case of mixed positive and negative clouds.
@param hdr (hdrinf *) Properly configured hdrinf struct
@param sd (srd *) Properly configured subring descriptor
@param modpar (float *) Properly configured subring parameter array
@param nr (int) Number of subrings
@param cflux (double *) Cloudflux as determined in the ringparms struct
@param radsep (double) Separation of subrings in pixel
@param srnr (int) Subring number
@param disk (int) Disk number
@return void
*/
/* ------------------------------------------------------------ */
#ifdef PBCORR
static int srput_mixed(void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long grid), struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk);
#else
static int srput_mixed(struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk);
#endif
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int metropolis(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Metropolis algorithm
This is the part where the Metropolis iterations are done.
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) fit parameter information struct
@return (success) int metropolis: 1
(error) 0
*/
/* ------------------------------------------------------------ */
/* static int metropolis(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int genfit(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Generic gft fit algorithm
This is the part where the generic fitting with gft is done.
@param startifv (startinf *) Properly configured startinf struct
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) fit parameter information struct
@return (success) int genfit: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int genfit(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void destroyinlistel(inlistel *first)
@brief Destructor of a inlistel list
Destroys a inlistel list from first on. The element before first will
not be terminated, while the list has to be terminated.
@param first (inlistel *) The first inlistel element to destroy(or NULL)
@return void
*/
/* ------------------------------------------------------------ */
static void destroyinlistel(inlistel *first);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int decodestr(char *string, int *array, int max)
@brief decodes an input string
The input string of varymult and varystr has to be a:b where a is
less or equal b, b is less than the number of rings (in this
function given by the max parameter), and a is greater than 0. If
the string is of that structure, the function returns 1 and a and b
are put into array as integers, 0 otherways.
@param string (char *) Input string
@int array (int *) Array to contain a and b
@param max (int) The maximum value that may be read
@return (success) int decodestr 1
(error) 0
*/
/* ------------------------------------------------------------ */
/* static int decodestr(char *string, int *array, int max); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void prepout(loginf *log, headerinf *hdr, ringparms *rpm)
@brief Opens a file and puts an old-style ascii header to the top
Opens a file and puts an ascii header to the top, as in the old
version of tirific. This function needs ftstab to be initialised as
is done in get_ringparms(). The result is put to the component tstream of log.
@param log (loginf *) Log description object
@param hdr (hdrinf *) header description object
@param rpm (ringparms *) Ring parameter description object
@return void
*/
/* ------------------------------------------------------------ */
static void prepout(loginf *log, hdrinf *hdr, ringparms *rpm);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void writeoutput(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, double dof, int modcount, double rchisq)
@brief Writes the information contained in rpm -> oldpar to the output
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Fit parameter information struct
@param accept (char) Indicator whether the last model was accepted
@param dof (double) Degrees of freedom
@param modcount (int) Number of the model
@param rchisq (double) Reduced chi2
@return void
*/
/* ------------------------------------------------------------ */
static void writeoutput(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, double dof, int modcount, double rchisq);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void writeoutputread(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, double dof, int modcount, double rchisq)
@brief Writes the information contained in rpm -> oldpar to the output
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Fit parameter information struct
@param accept (char) Indicator whether the last model was accepted
@param dof (double) Degrees of freedom
@param modcount (int) Number of the model
@param rchisq (double) Reduced chi2
@return void
*/
/* ------------------------------------------------------------ */
static void writeoutputread(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, double dof, int modcount, double rchisq);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void writeouttext(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, int dof, int modcount)
@brief Writes the information contained in rpm -> oldpar to the text output only
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Fit parameter information struct
@param accept (char) Indicator whether the last model was accepted
@param dof (int) Degrees of freedom
@param modcount (int) Number of the model
@param proba (double) Probability of acceptance
@return void
*/
/* ------------------------------------------------------------ */
/* static void writeouttext(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, int dof, int modcount, double proba); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void writeoutarray(loginf *log, hdrinf *hdr, ringparms *rpm, double *par, char accept, double chisquare, int modcount, double dof, double chisquare_red)
@brief Writes the information contained in par to the output array of rpm
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param par (double *) The input parameter array
@param accept (char) Indicator whether the last model was accepted
@param chisquare (double) Degrees of freedom
@param modcount (int) Number of the model
@param dof (double) Degrees of freedom
@param chisquare_red (double) reduced chisquare, direct input
@return void
*/
/* ------------------------------------------------------------ */
static void writeoutarray(loginf *log, hdrinf *hdr, ringparms *rpm, double *par, char accept, double chisquare, int modcount, double dof, double chisquare_red);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void writeoutarrayerr(hdrinf *hdr, ringparms *rpm, double *par, double *errors, char accept, double chisquare, int modcount, double dof)
@brief Writes the information contained in rpm -> par to the output array errors
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param par (double *) array containing errors in intrinsic units, must have length of any output array
@param errors (double *) output array, must have length of any output array
@param accept (char) Indicator whether the last model was accepted
@param chisquare (double) Degrees of freedom
@param modcount (int) Number of the model
@param dof (double) Degrees of freedom
@return void
*/
/* ------------------------------------------------------------ */
static void writeoutarrayerr(hdrinf *hdr, ringparms *rpm, double *par, double *errors, char accept, double chisquare, int modcount, double dof);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int chprm_metro(varlel *varylist, double *oldpar, double *newpar, maths_rstr *rnd, double deltfact)
@brief Changes the parameters in par according to varylist
Each parameter that is contained in the parameter lists of varylist
will be changed randomly. It will be increased or diminished by a
number in-between 0 and the delta of the element of the
varylist. All parameters adressed in one varylist component will be
changed by the same amount. The output is into newpar, while oldpar
contains the input parameters to change.
@param varylist (varlel *) Information structure to vary the
parameters (must be properly configured according to par)
@param oldpar (double *) Old parameter list
@param newpar (double *) New parameter list
@param rnd (maths_rstr *) An initialised random generator struct
@param loopnr (double) Number of actual loop
@return int chprm_metro: 1 if successful, 0 if a given number FALSEATTEMPTS of attempts to change the model towards an invalid value is exceeded.
*/
/* ------------------------------------------------------------ */
/* static int chprm_metro(varlel *varylist, double *oldpar, double *newpar, maths_rstr *rnd, long loopnr); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int chprm_gen(double *parms; varlel *varylist, double *newpar)
@brief Changes the parameters in par according to parms
Each parameter that is contained in the parameter lists of varylist
will be changed according to the parms array as passed by the gft
fit routine. parms should contain as many parameters as varlel
elements are present in the ll. Differences in the actual
parameters are kept.
@param parms (double *) Parameters as passed by the gft routine
@param varylist (varlel *) Information structure to vary the
parameters (must be properly configured according to par)
@param newpar (double *) New parameter list
@return int chprm_gen: 0 if successful, n>0 counting the parameters
out-of-range. The changes will take place nevertheless.
*/
/* ------------------------------------------------------------ */
static int chprm_gen(double *parms, varlel *varylist, double *newpar);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static float zprof(int option, maths_rstrf *permrandstr)
@brief Delivers a random variable according to a profile identifyer
Function to get random deviates for various functions. The double
precision variable fdev contains the random deviate. If nran is
within a factor two of the largest possible integer then integer
overflow could occur. DOUBLE PRECISION FUNCTION
fdev(option,nran,iran,idum) Type of distribution function for the
random deviates.
Options:
option = 1 -- Gaussian deviates.
option = 2 -- Sech2 deviates.
option = 3 -- Exponential deviates.
option = 4 -- Lorentzian deviates.
option = 5 -- Box deviates. (is also default)
option = 6 -- Reset the rng for gaussian
@param option (int) The type of the random variate
@param permrandstrf (maths_rstr *) An initialised random number control object from this module
@return float zprof: A random number distributed specified by option
*/
/* ------------------------------------------------------------ */
static float zprof(int option, maths_rstrf *permrandstr, float *y2);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void hdl_init(int ndisks)
@brief Initializes the standard header context table
@param ndisks (int) Number of disks
*/
/* ------------------------------------------------------------ */
static int hdl_init(int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int create_hdu_3(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
@brief Opens if necessary creates the third hdu
Will Create a third hdu of the logfile.
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Fit parameter information struct
@return (success) int create_hdu_3: 0\\
(error) 1
*/
/* ------------------------------------------------------------ */
/* static int create_hdu_3(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int open_hdu_3(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
@brief Opens if necessary creates the third hdu
Will Create a third hdu of the logfile.
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Fit parameter information struct
@return (success) int create_hdu_3: 0 \\
(error) 1: Memory error
2: User decides not to fit
*/
/* ------------------------------------------------------------ */
static int open_hdu_3(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int create_hdu_1(log, hdr, rpm, fit)
@brief Creates a fits table and puts the global information to the fits table
Will create a ftstab fits table with the first hdu from the
information acquired in the description objects.
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Fit parameter information struct
@return (success) int create_hdu_1: 0\\
(error) 1
*/
/* ------------------------------------------------------------ */
/* static int create_hdu_1(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int create_hdu_2(char *logname, varlel *varylist, varlel **pointarray, int nur, hdrinf *hdr)
@brief Creates a second hdu of a fits table and puts the fit
information contained in the varlel ll to the fits table
Creates a second hdu of a fits table (deleting consequent elements)
and puts the fit information contained in the varlel ll to the fits
table. For a proper functionality make sure that the first hdu is already created.
@param logname (char *) The name of the logfile
@param varylist (varlel *) A properly configured varylist
@param pointarray (varlel **) Array with pointers to varlels of the size of elements of deltas given by the user
@param nur (int) Number of rings
@param hdr (hdrinf *) Properly configured headerinf struct
@return (success) int create_hdu_1: 0\\
(error) 1
*/
/* ------------------------------------------------------------ */
/* static int create_hdu_2(char *logname, varlel *varylist, varlel **pointarray, int nur, hdrinf *hdr); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int change_hdu_2(varlel *varylist, varlel **pointarray, int nur, hdrinf *hdr)
@brief Creates a second hdu of a fits table and puts the fit
information contained in the varlel ll to the fits table
Changes a second hdu of a fits table (deleting consequent elements)
and puts the fit information contained in the varlel ll to the fits
table. For a proper functionality make sure that the first hdu is already created and the second is opened. This is only of use if both tables have the identical size.
@param varylist (varlel *) A properly configured varylist
@param pointarray (varlel **) Array with pointers to varlels of the size of elements of deltas given by the user
@param nur (int) Number of rings
@param hdr (hdrinf *) Properly configured headerinf struct
@return (success) int change_hdu_2: 0\\
(error) 1
*/
/* ------------------------------------------------------------ */
/* static int change_hdu_2(varlel *varylist, varlel **pointarray, int nur, hdrinf *hdr); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int primpos_numtype(int ident)
@brief Returns the ftstab numerical type of a PRIMPOS identifyer
@param ident (int) PRIMPOS idendifyer
@return int primpos_numtype: Numerical type identifyer as in ftstab module
*/
/* ------------------------------------------------------------ */
/* static int primpos_numtype(int ident); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double primpos_value(int ident, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Returns the value of a PRIMPOS identifyer from a varele pointer
@param ident (int) identifyer
@param log (loginf *) log information struct
@param hdr (hdrinf *) header information struct
@param rpm (ringparms *) Ring parameter information struct
@param fit (fitparms *) Fit parameter information struct
@return double primpos_value: value of a PRIMPOS identifyer
*/
/* ------------------------------------------------------------ */
/* static double primpos_value(int ident, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double secpos_value(int ident, varele *varylist, int nur, hdrinf *hdr, int element)
@brief Returns the value of a SECPOS identifyer from a varele pointer
@param ident (int) SECPOS idendifyer
@param varylist (varele *) pointer to the varele from which the values are extracted
@param nur (int) Number of rings
@param hdr (hdrinf *) Properly configured headerinf struct
@param element (int) Number of the element (start with 0) in case of ELEMENTS
@return double secpos_value: value of a SECPOS identifyer
*/
/* ------------------------------------------------------------ */
/* static double secpos_value(int ident, varlel *varylist, int nur, hdrinf *hdr, int element); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int comparevarlel(varlel *varlel1, varlel *varlel2)
@brief Checks if the varlels are identical
@param varlel1 (varlel *) first varlel element
@param varlel2 (varlel *) second varlel element
@return int comparevarlel: 0 if they contain identical values, 1 if they are fatally different, -1, if they are different but contain the same number of elements
*/
/* ------------------------------------------------------------ */
/* static int comparevarlel(varlel *varlel1, varlel *varlel2); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int fillhdvarele(varlel *varele, int i, double *array,
int parameter, double *parmax, double *parmin, int *moderate, double
*delstart, double *delend, int *itestart, int *iteend, double
*satdelt, double *mindelta, hdrinf *hdr, loginf *log)
@brief Puts the values of the arrays into varele, checking for mismatch with array
Puts the values of the global variables of a varele struct into
varele from the single arrays, checking for mismatch with the
content of array. If there is any mismatch the user will be
prompted. Will return 1 if the user decides to abort. Will return 0
if the user does not want to abort. The user is only prompted once
and the keyword "proceed" has to be canceled afterwards.
@param varele (varlel *) An element of the varlist
@param i (int) The position in the arrays
@param parameter (int) The parameter identification
@param array (double *) The array that will be checked
@param parmax (double *) Parameter list with maxima
@param parmin (double *) Parameter list with minima
@param moderate (int *) Parameter list with moderate values
@param delstart (double *) Parameter list with delstart values
@param delend (double *) Parameter list with delend values
@param itestart (int *) Parameter list with itestart values
@param iteend (int *) Parameter list with iteend values
@param satdelt (double *) Parameter list with satdelt values
@param mindelta (double *) Parameter list with mindelta values
@param hdr (hdrinf *) Properly configured hdrinf struct
@param log (loginf *) Properly configured loginf struct
@return int fillhdvarele 1 In case of an error, 0 if everything is ok
*/
/* ------------------------------------------------------------ */
/* static int fillhdvarele(varlel *varele, int i, double *array, int parameter, double *parmax, double *parmin, int *moderate, double *delstart, double *delend, int *itestart, int *iteend, double *satdelt, double *mindelta, hdrinf *hdr, loginf *log); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int putmetresults(loginf *log, ringparms *rpm, fitparms *fit)
@brief Calculates and puts the results of the fitting procedure
This function needs the logfile opened by ftstab module at the third
extension
@param log (loginf *) Properly configured loginf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int putresults: 1
(error) 0
*/
/* ------------------------------------------------------------ */
/* static int putmetresults(loginf *log, ringparms *rpm, fitparms *fit); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int putgenresults(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Calculates and puts the results of the fitting procedure
This function needs the logfile opened by ftstab module at the third
extension
@param startinfv (startinf *) Properly configured loginf struct
@param log (hdrinf *) Properly configured hdrinf struct
@param log (loginf *) Properly configured loginf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int putresults: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int putgenresults(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int golden_section(startinf *startinfv, loginf *log, ringparms *rpm, fitparms *fit)
@brief A golden section iteration
The other working horse, a golden section iteration.
@param startinfv (startinf *) Properly configured loginf struct
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return int golden_section: Always 1...
*/
/* ------------------------------------------------------------ */
static int golden_section(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int putgoldresults(loginf *log, ringparms *rpm, fitparms *fit)
@brief Calculates and puts the results of the fitting procedure
This function needs the logfile opened by ftstab module at the third
extension
@param log (loginf *) Properly configured loginf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int putresults: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int putgoldresults(loginf *log, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int writeasctable(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
@brief Writes an ascii table with the results
This function needs the logfile opened by ftstab module at the third
extension
@param startinfv (startinf *) Properly configured loginf struct
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int writeasctable: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int writeasctable(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int writebigasctable(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
@brief Writes an ascii table with the results
This function needs the logfile opened by ftstab module at the third
extension. This will list all properties for the subrings.
@param startinfv (startinf *) Properly configured startinf struct
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int writeasctable: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int writebigasctable(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int coolgal(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Produces a 3d fits image of the model.
Prompts the user for a name (hidden) of an output cube. This will be a 3d image of the galaxy. As a smoothing value the largest hpbw is used in all three directions. This function will deallocate and reallocate the model and the original cube, such that this function should be called last before the program is being left. The extension of the output cube in the third dimension is the largest dimension in x-y.
@param startinfv (startinf *) Properly configured startinf struct
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int coolgal: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int coolgal(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static qfits_header *makecoolhdr(hdrinf *hdr, double beamsizeindeg)
@brief Produces a header struct for coolgal output
Produces a qfits_header object suitable for the coolgal output.
@param hdr (hdrinf *) Properly configured hdrinf struct
@param beamsizeindeg (double *) 1d beam size in degrees
@return (success) qfits_header *makecoolhdr: The properly configured header
(error) NULL
*/
/* ------------------------------------------------------------ */
static qfits_header *makecoolhdr(hdrinf *hdr, double beamsizeindeg);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int makecoolpoints(Cube *cube, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Makes a 3d pointsource model and packs in on cube
@param cube (Cube *) The cube onto which the model is gridded
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param rpm (fitparms *) Properly configured fitparms struct
@return (success) int makecoolpoints: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int makecoolpoints(Cube *cube, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void tirout_a(simparse_scn_arel **arel, FILE *stream, char *keyword, char *input, fitparms *fit)
@brief Copies a part of the tirific input to a stream
@param stream (FILE *) An open stream
@param keyword (char *) Name of the keyword as given in gipsy
@param input (char *) Allocated string of length VARYHSTRELES (including terminating '\0')
@return tirout_a (success) 0
(error) 1
*/
/* ------------------------------------------------------------ */
static int tirout_a(simparse_scn_arel **arel, FILE *stream, char *keyword);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int tirout(startinf *startinfv, loginf *log, ringparms *rpm, fitparms *fit, int nrplts)
@brief Produces one or two tirific logfiles containing the results
@param startifv (startinf *) Properly configured startinf struct
@param log (loginf *) Properly configured loginf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@param nrplts (int) Number of plots as inquired with graphout()
@return (success) int tirout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int tirout(startinf *startinfv, loginf *log, ringparms *rpm, fitparms *fit, int nrplts);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int progressout(startinf *startinfv, char *message)
@brief Produces a file containing only the message
Kamphuis addition
@param startifv (startinf *) Properly configured startinf struct
@param message (char *)
@return (success) int progressout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int progressout(startinf *startinfv, char *message);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int progressfinished(startinf *startinfv)
@brief Appends a message to the progress file at the end of the fitting procedure.
Kamphuis addition
@param startifv (startinf *) Properly configured startinf struct
@return (success) int tirout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int progressfinished(startinf *startinfv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int histout(ringparms *rpm)
@brief Produces the histogram output of tirific
@param rpm (ringparms *) Properly configured ringparms struct
@return (success) int tirout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
/* static int histout(ringparms *rpm); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int rectout(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Produces the rectify output of tirific
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int rectout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
/* static int rectout(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void rectout_a(FILE *stream)
@brief Output of fixed stuff to a file
@param stream (FILE *) An open stream
@return void
*/
/* ------------------------------------------------------------ */
/* static void rectout_a(FILE *stream); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void rectout_b(FILE *stream)
@brief Output of fixed stuff to a file
@param stream (FILE *) An open stream
@return void
*/
/* ------------------------------------------------------------ */
/* static void rectout_b(FILE *stream); */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int tiltout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Produces the tiltogram output of tirific
@param startinfv (startinf *) Properly configured startinf struct
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int tiltout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int tiltout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int briggsout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Produces a tip-lon diagram
@param startinfv (startinf *) Properly configured startinf struct
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int graphout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int briggsout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int graphout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
@brief Produces the graphics output of tirific
@param startinfv (startinf *) Properly configured startinf struct
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (fitparms *) Properly configured fitparms struct
@return (success) int graphout: 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int graphout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int get_graphnr(char *string, int ndisks)
@brief Identifies a graphics output number
@param string (char *) String to identify
@param ndisks (int) Number of disks
@return (success) int get_graphnr: Number of the graphics number as defined by _GRAPHNR plus NPARAMS
(error) 0
*/
/* ------------------------------------------------------------ */
static int get_graphnr(char *string, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gr_fillscaling(loginf *log, hdrinf *hdr, int ident, float *scale, float *zero, int ndisks)
@brief Returns the scale for one unit to the alternative unit
The plot output of tirific imposes two axis descriptions on the
plots. The scales are connected via valright =
scale*valleft+zero. This function returns these values.
@param log (loginf *) Properly configured loginf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param ident (int) Identification as output of ftstab_gtitln_ or get_graphnr
@param scale (float *) The scale from left hand border to right hand border of a plot (output)
@param scale (float *) The zero from left hand border to right hand border of a plot (output)
@param ndisks (int) Number of disks
@return (success) int get_graphnr: Number of the graphics number as defined by _GRAPHNR plus NPARAMS
(error) 0
*/
/* ------------------------------------------------------------ */
static void gr_fillscaling(loginf *log, hdrinf *hdr, int ident, float *scale, float *zero, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gr_fillaxis(int ident, char *string, int ndisks)
@brief Returns an axis descriptor string suitable for the use in the pgp module
It is no error to pass NULL.
@param ident (int) Identification as output of ftstab_gtitln_ or get_graphnr
@param string (char *) String to fill (At least characters) or NULL
@param ndisks (int) Number of disks
@return void
*/
/* ------------------------------------------------------------ */
static void gr_fillaxis(int ident, char *string, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gr_fillunit(int ident, char *string, int ndisks)
@brief Returns an unit string suitable for the use in the pgp module
It is no error to pass NULL.
@param ident (int) Identification as output of ftstab_gtitln_ or get_graphnr
@param string (char *) String to fill (At least characters) or NULL
@param ndisks (int) Number of disks
@return void
*/
/* ------------------------------------------------------------ */
static void gr_fillunit(int ident, char *string, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gr_fillaltunit(int ident, char *string, int ndisks)
@brief Returns an alternative unit string suitable for the use in the pgp module
It is no error to pass NULL.
@param ident (int) Identification as output of ftstab_gtitln_ or get_graphnr
@param string (char *) String to fill (At least characters) or NULL
@param ndisks (int) Number of disks
@return void
*/
/* ------------------------------------------------------------ */
static void gr_fillaltunit(int ident, char *string, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gr_filllegend(int ident, char *string, int ndisks)
@brief Returns a legend string suitable for the use in the pgp module
It is no error to pass NULL.
@param ident (int) Identification as output of ftstab_gtitln_ or get_graphnr
@param string (char *) String to fill (At least characters) or NULL
@param ndisks (int) Number of disks
@return void
*/
/* ------------------------------------------------------------ */
static void gr_filllegend(int ident, char *string, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int fillgrapharray(startinf *startinfv, hdrinf *hdr, ringparms *rpm, decomp_inlist *index, int ident, float *array, float *larray, int ndisks)
@brief Fills two arrays for graphics use
The arrays array and larray are filled with the values contained in
rpm -> par and rpm -> modpar according to the parameter
required. par and modpar should contain the values in user
units. The parameter is decoded via an integer ident as returned by
get_graphident(). array and larray should be large enough.
@param startinfv (startinf *) Properly configured startinf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured rinparms struct
@param index (decomp_inlist *) Index list as defined in simparse
@param ident (int) Identity of the value asked for as given by get_graphident()
@param array (float *) Array that contains the ring parameters
@param errarr
@param larray (float *) Array containing the subring parameters
@param ndisks (int) Number of disks
@return (success) 1
(error) 0
*/
/* ------------------------------------------------------------ */
static int fillgrapharray(startinf *startinfv, hdrinf *hdr, ringparms *rpm, int ident, float *array, float *larray, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int gr_deleteindexed(int nur, int ident, float *xarray, float *yarray, float *yerrarray, decomp_inlist *index, int ndisks);
)
@brief Deletes indexed points from three arrays
Uses an index list as defined in simparse to identify indexed
parameters in xarray, yarray, and yerrarray and deletes them. The
arrays are not reallocated, but all parameters are shift towards a
lower index if a data point is on the index. Returns the number of
points that are not on the index.
@param nur (int) Number of rings
@param ident (int) Identity of the parameter asked for as returned by get_graphident()
@param xarray (float *) Array, x-axis
@param yarray (float *) Array, y-axis
@param yerrarray (float *) Array, errors
@param index (decomp_inlist *) index list as defined in simparse
@param ndisks (int) Number of disks
@return int gr_deleteindexed: number of parameters not on the index
*/
/* ------------------------------------------------------------ */
static int gr_deleteindexed(int nur, int ident, float *xarray, float *yarray, float *yerrarray, decomp_inlist *index, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int get_graphident(char *string, char *axis, char *unit, char *altunit, char *legend, int ndisks)
@brief Returns the identifyer of a graphics output
The function returns the identifyer of a graphics output identifyer. The value is not negative if the string input is identified with a variable parameter, or with a valid other graphics output keystring. In case of a variable parameter identifyer, this is identical with the RADI, etc identifyer, otherways with the NPARAMS+WANGLE_GRAPHNR, ... . At the same time the strings axis unit and legend are filled with appropriate values to produce an output with the pgp module. If the value of axis, unit, and legend are NULL, this is no error. If, however, one of those is not NULL, the strings must have at least a minimum length as given below.
@param string (char *) Input string that should be scanned
@param axis (char *) Output, axis descriptor string (at least 4 characters)
@param unit (char *) Output, unit string (at least 30 characters)
@param altunit (char *) Output, Alternative unit string to the right (top) axis (at least 30 characters)
@param legend (char *) Output, legend string (at least 80 characters)
@param ndisks (int) Input, number of disks
@return (success) int get_graphident: Identification for a graphics output
(error) -1 In case of an invalid string
*/
/* ------------------------------------------------------------ */
static int get_graphident(char *string, char *axis, char *unit, char *altunit, char *legend, int ndisks);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int renzo(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm)
@brief Produces a renzogram with the rings
@param startinfv (startinf *) Properly configured startinf struct
@param hdr (hdrinf *) Properly configured hdrinf struct
@param rpm (ringparms *) Properly configured ringparms struct
@return (success) int renzo: 0
(error) 1
*/
/* ------------------------------------------------------------ */
static int renzo(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static qfits_header *makerenzohdr(hdrinf *hdr, int planes, int refine)
@brief Produces a header struct for renzogram output
Produces a qfits_header object suitable for the renzogram output.
@param hdr (hdrinf *) Properly configured hdrinf struct
@param planes (int) Number of planes
@param refine (int) How many pixels in the outcube fit in one pixel of the incube.
@return (success) qfits_header *makecoolhdr: The properly configured header
(error) NULL
*/
/* ------------------------------------------------------------ */
static qfits_header *makerenzohdr(hdrinf *hdr, int planes, int refine);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int destroy_inf_sdis(inf_sdis *int_sdisv)
@brief deallocates an inf_sdis struct
@param int_sdisv (hdrinf *) sdis struct
@return (success) 0
(error) 1
*/
/* ------------------------------------------------------------ */
static int destroy_inf_sdis(inf_sdis *int_sdisv);
static int destroy_inf_vrad(inf_vrad *int_vradv);
static int destroy_inf_vver(inf_vver *int_vverv);
static int destroy_inf_dvro(inf_dvro *int_dvrov);
static int destroy_inf_dvra(inf_dvra *int_dvrav);
static int destroy_inf_dvve(inf_dvve *int_dvvev);
static int destroy_inf_vm0(inf_vm0 *int_vm0v);
static int destroy_inf_vm1(inf_vm1 *int_vm1v);
static int destroy_inf_vm2(inf_vm2 *int_vm2v);
static int destroy_inf_vm3(inf_vm3 *int_vm3v);
static int destroy_inf_vm4(inf_vm4 *int_vm4v);
static int destroy_inf_ra1(inf_ra1 *int_ra1v);
static int destroy_inf_ra2(inf_ra2 *int_ra2v);
static int destroy_inf_ra3(inf_ra3 *int_ra3v);
static int destroy_inf_ra4(inf_ra4 *int_ra4v);
static int destroy_inf_ro1(inf_ro1 *int_ro1v);
static int destroy_inf_ro2(inf_ro2 *int_ro2v);
static int destroy_inf_ro3(inf_ro3 *int_ro3v);
static int destroy_inf_ro4(inf_ro4 *int_ro4v);
static int destroy_inf_wm0(inf_wm0 *int_wm0v);
static int destroy_inf_wm1(inf_wm1 *int_wm1v);
static int destroy_inf_wm2(inf_wm2 *int_wm2v);
static int destroy_inf_wm3(inf_wm3 *int_wm3v);
static int destroy_inf_wm4(inf_wm4 *int_wm4v);
static int destroy_inf_ls0 (inf_ls0 *int_ls0v);
static int destroy_inf_lc0 (inf_lc0 *int_lc0v);
static int destroy_inf_smi (inf_smi *inf_smiv);
static int destroy_inf_gau (inf_gau *inf_gauv);
static int destroy_inf_azi (inf_azi *inf_gauv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static inf_sdis *create_inf_sdis(void)
@brief Allocates an sdis struct and substructures
@param void
@return (success) pointer to inf_sdis struct
(error) NULL
*/
/* ------------------------------------------------------------ */
static inf_sdis *create_inf_sdis(void);
static inf_vrad *create_inf_vrad(void);
static inf_vver *create_inf_vver(void);
static inf_dvro *create_inf_dvro(void);
static inf_dvra *create_inf_dvra(void);
static inf_dvve *create_inf_dvve(void);
static inf_vm0 *create_inf_vm0(void);
static inf_vm1 *create_inf_vm1(void);
static inf_vm2 *create_inf_vm2(void);
static inf_vm3 *create_inf_vm3(void);
static inf_vm4 *create_inf_vm4(void);
static inf_ra1 *create_inf_ra1(void);
static inf_ra2 *create_inf_ra2(void);
static inf_ra3 *create_inf_ra3(void);
static inf_ra4 *create_inf_ra4(void);
static inf_ro1 *create_inf_ro1(void);
static inf_ro2 *create_inf_ro2(void);
static inf_ro3 *create_inf_ro3(void);
static inf_ro4 *create_inf_ro4(void);
static inf_wm1 *create_inf_wm1(void);
static inf_wm0 *create_inf_wm0(void);
static inf_wm2 *create_inf_wm2(void);
static inf_wm3 *create_inf_wm3(void);
static inf_wm4 *create_inf_wm4(void);
static inf_ls0 *create_inf_ls0 (void);
static inf_lc0 *create_inf_lc0 (void);
static inf_smi *create_inf_smi (void);
static inf_gau *create_inf_gau (void);
static inf_azi *create_inf_azi (void);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int chkb_zero(ringparms *rpm, fitparms *fit, int ident)
@brief check if the function should be activated
Basically checks if the parameter with the name ident is nonzero in the input and if it is fitted.
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (ringparms *) Properly configured fitparms struct
@param ident (int *) identification (PXXX)
@return 0: activate function (either nonzero or fitted)
1: do not activate function
*/
/* ------------------------------------------------------------ */
static int chkb_zero(ringparms *rpm, fitparms *fit, int ident);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int chkb_val(ringparms *rpm, fitparms *fit, int ident, double val)
@brief check if the function should be activated
Basically checks if the parameter with the name ident is not val in the input and if it is fitted.
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (ringparms *) Properly configured fitparms struct
@param ident (int *) identification (PXXX)
@param val (double *) The value that every parameter should have
@return 0: activate function (either non-90 or fitted)
1: do not activate function
*/
/* ------------------------------------------------------------ */
static int chkb_val(ringparms *rpm, fitparms *fit, int ident, double val);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int chkb_sdis(ringparms *rpm, fitparms *fit)
@brief Optionally allocates and puts correct switches in the sdis struct
Basically checks in which way the ring-dependent dispersion is taken
into account, allocates (or doesn't allocate) structures and sets
the correct function pointers. If the dispersion is 0 throughout and
is not fitted, no random component is added to the velocity of point
sources (otherways, a random component is calculated, but it is 0
anyway).
@param rpm (ringparms *) Properly configured ringparms struct
@param fit (ringparms *) Properly configured fitparms struct
@return (success) 0
(error) 1: memory problems
*/
/* ------------------------------------------------------------ */
static int chkb_sdis(ringparms *rpm, fitparms *fit);
static int chkb_vrad(ringparms *rpm, fitparms *fit);
static int chkb_vver(ringparms *rpm, fitparms *fit);
static int chkb_dvro(ringparms *rpm, fitparms *fit);
static int chkb_dvra(ringparms *rpm, fitparms *fit);
static int chkb_dvve(ringparms *rpm, fitparms *fit);
static int chkb_vm0 (ringparms *rpm, fitparms *fit);
static int chkb_vm1(ringparms *rpm, fitparms *fit);
static int chkb_vm2(ringparms *rpm, fitparms *fit);
static int chkb_vm3(ringparms *rpm, fitparms *fit);
static int chkb_vm4(ringparms *rpm, fitparms *fit);
static int chkb_ra1(ringparms *rpm, fitparms *fit);
static int chkb_ra2(ringparms *rpm, fitparms *fit);
static int chkb_ra3(ringparms *rpm, fitparms *fit);
static int chkb_ra4(ringparms *rpm, fitparms *fit);
static int chkb_ro1(ringparms *rpm, fitparms *fit);
static int chkb_ro2(ringparms *rpm, fitparms *fit);
static int chkb_ro3(ringparms *rpm, fitparms *fit);
static int chkb_ro4(ringparms *rpm, fitparms *fit);
static int chkb_wm0 (ringparms *rpm, fitparms *fit);
static int chkb_wm1(ringparms *rpm, fitparms *fit);
static int chkb_wm2(ringparms *rpm, fitparms *fit);
static int chkb_wm3(ringparms *rpm, fitparms *fit);
static int chkb_wm4(ringparms *rpm, fitparms *fit);
static int chkb_ls0 (ringparms *rpm, fitparms *fit);
static int chkb_lc0 (ringparms *rpm, fitparms *fit);
static int chkb_smi (ringparms *rpm, fitparms *fit);
static int chkb_gau (ringparms *rpm, fitparms *fit);
static int chkb_azi (ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void rndmf_init_sdis_pas(ringparms *rpm, int srnr, int disk)
@brief Initialises the rng internal to the calulation of sdis
@param rpm (void *) properly allocated ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void rndmf_init_sdis_act(void *rpm, int srnr, int disk);
static void rndmf_init_gau_act(void *rpm, int srnr, int i, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void rndmf_init_sdis_pas(void *rpm, int srnr, int disk)
@brief dummy function doing nothing instead of rndmf_init_sdis_act
@param rpm (void *) meaningless
@param srnr (int) meaningless
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void rndmf_init_sdis_pas(void *rpm, int srnr, int disk);
static void rndmf_init_gau_pas(void *rpm, int srnr, int i, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void chclfl_sdis_act(void *rpm, int srnr, int disk)
@brief Change the cloud flux and the cloud numbers depending on the number of subrings
@param rpm (void *) properly configured ringparms struct, casted to void
@param srnr (int) subring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void chclfl_sdis_act(void *rpm, int srnr, int disk);
static void chclfl_sdis_pas(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_sdis_empty_act(void *rpm, int srnr, int disk)
@brief Use the random number generator instead of creating point sources
@param rpm (void *) properly configured ringparms struct, casted to void
@param srnr (int) subring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_sdis_empty_act(void *rpm, int srnr, int disk);
static void pr_sdis_empty_pas(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_sdis_repeater_act(void *rpm, int srnr, int disk)
@brief Repeat a sequence of changing the velocity and gridding
@param rpm (void *) properly configured ringparms struct, casted to void
@param pp, (float *) point source coordinates
@param vold (float) old velocity of point source
@param srnr (int) subring number
@param hdr (hdrinf *) properly configured hdrinf struct
@param j (long *) point source number
@param signum (int) signum of flux of point source
@param npoints (long *) number of points
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void sdis_repeater_act(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk);
static void sdis_repeater_pas(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_sdis_act(ringparms *rpm, float v, int srnr, int disk)
@brief calculates random velocity component and adds it to the input
@param rpm (ringparms *) Properly structured ringparms struct
@param v (float *) Original velocity on input, will be changed
@param vold (float *) Output: original velocity on input
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_sdis_act(void *rpm, float *v, float *vold, int srnr, int disk);
static void pr_vrad_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/* Note that the whole 6d point must be passed */
static void pr_vver_act(void *rpm, float *point, int srnr, int disk);
static void pr_dvro_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_dvra_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_dvve_act(void *rpm, float *v, int srnr, int disk);
static void pr_dvro_act2(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_dvra_act2(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_dvve_act2(void *rpm, float *v, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gau_getcloudnumber_act(ringparms *rpm, int srnr, int number, int disk)
@brief returns a cloud number solving an integral
Gaussian spiral arm or bar, generating cloud number for Gaussian number
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param number (int) Number of arm
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void gau_getcloudnumber_act(void *rpm, int srnr, int number, int disk);
/* Dummy instead */
static void gau_getcloudnumber_pas(void *rpm, int srnr, int number, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void gau_getaz(ringparms *rpm, int pgaip, maths_rstrf *randstr, int pgaid, float *az, float *sinaz, float *cosaz, int srnr, int disk)
@brief returns an azimuth
Returns new azimuth of point source, for a given Gaussian
@param rpm (ringparms *) Properly structured ringparms struct
@param pgaip (int) Number of parameter for the Gaussian phase, PGA1P, PGA2P, PGA3P, or PGA4P
@param randstr (maths_rstrf) Randum number generator struct, gau_inf -> randstr1/randstr2/randstr3/randstr4
@param pgaid (int) Number of parameter for the Gaussian dispersion, 0, 1, 2, or 3
@param az (float *) Output: azimuth
@param cosaz (float *) Output: cosine of azimuth
@param sinaz (float *) Output: sine of azimuth
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void gau_getaz(ringparms *rpm, int pgaip, maths_rstrf *randstr, int pgaid, float *az, float *sinaz, float *cosaz, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_vver_rota_act(void *rpm, float *vz, float *vz2, int srnr, int disk)
@brief Adds the cosine component when rotating about
inclination, in case that the vertical velocity is nonzero
@param rpm (ringparms *) Properly structured ringparms struct
@param vz (float *) Original velocity on input, z component
@param vz2 (float *) Original velocity on output, z-component, will be changed
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_vver_rota_act(void *rpm, float *vz, float *vz2, int srnr, int disk);
static void pr_vver_rota_pas(void *rpm, float *vz, float *vz2, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_vmi_pas(void *rpm, int srnr, int disk)
@brief dummy instead of pr_m1_act
@param rpm (void *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_vmi_pas(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_wm1s_act(ringparms *rpm int srnr, int disk)
@brief calculates warp sin component and adds it to the subring
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_wm1s_act(void *rpm, int srnr, int disk);
static void srpr_wm2s_act(void *rpm, int srnr, int disk);
static void srpr_wm3s_act(void *rpm, int srnr, int disk);
static void srpr_wm4s_act(void *rpm, int srnr, int disk);
static void srpr_wm1c_act(void *rpm, int srnr, int disk);
static void srpr_wm2c_act(void *rpm, int srnr, int disk);
static void srpr_wm3c_act(void *rpm, int srnr, int disk);
static void srpr_wm4c_act(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_wmi_pas(void *rpm, int srnr, int disk)
@brief dummy instead of pr_m1_act
@param rpm (void *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_wmi_pas(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_vm1s_act(ringparms *rpm int srnr, int disk)
@brief calculates velocity sin component and adds it to the subring
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_vm1s_act(void *rpm, int srnr, int disk);
static void srpr_vm2s_act(void *rpm, int srnr, int disk);
static void srpr_vm3s_act(void *rpm, int srnr, int disk);
static void srpr_vm4s_act(void *rpm, int srnr, int disk);
static void srpr_vm1c_act(void *rpm, int srnr, int disk);
static void srpr_vm2c_act(void *rpm, int srnr, int disk);
static void srpr_vm3c_act(void *rpm, int srnr, int disk);
static void srpr_vm4c_act(void *rpm, int srnr, int disk);
static void srpr_ra1s_act(void *rpm, int srnr, int disk);
static void srpr_ra2s_act(void *rpm, int srnr, int disk);
static void srpr_ra3s_act(void *rpm, int srnr, int disk);
static void srpr_ra4s_act(void *rpm, int srnr, int disk);
static void srpr_ra1c_act(void *rpm, int srnr, int disk);
static void srpr_ra2c_act(void *rpm, int srnr, int disk);
static void srpr_ra3c_act(void *rpm, int srnr, int disk);
static void srpr_ra4c_act(void *rpm, int srnr, int disk);
static void srpr_ro1s_act(void *rpm, int srnr, int disk);
static void srpr_ro2s_act(void *rpm, int srnr, int disk);
static void srpr_ro3s_act(void *rpm, int srnr, int disk);
static void srpr_ro4s_act(void *rpm, int srnr, int disk);
static void srpr_ro1c_act(void *rpm, int srnr, int disk);
static void srpr_ro2c_act(void *rpm, int srnr, int disk);
static void srpr_ro3c_act(void *rpm, int srnr, int disk);
static void srpr_ro4c_act(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_vmi_pas(void *rpm, float v, int srnr, float sinaz, float cosaz, int disk)
@brief dummy instead of pr_vm1-4s/c_act
@param rpm (void *) Properly structured ringparms struct
@param v (float *) Original velocity on input, will be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_vmi_pas(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_vm1s_act(ringparms *rpm, float v, int srnr, float sinaz, float cosaz, int disk)
@brief calculates s1 component and adds it to the input
@param rpm (ringparms *) Properly structured ringparms struct
@param v (float *) Original velocity on input, will be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_vm1s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm2s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm3s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm4s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm1c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm2c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm3c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm4c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_vm0_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra1s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra2s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra3s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra4s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra1c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra2c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra3c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ra4c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro1s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro2s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro3s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro4s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro1c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro2c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro3c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
static void pr_ro4c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_smi_pas(void *rpm, int srnr, int disk)
@brief dummy instead of pr_m1_act
@param rpm (void *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_smi_pas(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_sm1s_act(ringparms *rpm int srn, int diskr)
@brief calculates surface brightness sin component and adds it to the subring
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_sm0b_act(void *rpm, int srnr, int disk);
static void srpr_sm1s_act(void *rpm, int srnr, int disk);
static void srpr_sm2s_act(void *rpm, int srnr, int disk);
static void srpr_sm3s_act(void *rpm, int srnr, int disk);
static void srpr_sm4s_act(void *rpm, int srnr, int disk);
static void srpr_sm1c_act(void *rpm, int srnr, int disk);
static void srpr_sm2c_act(void *rpm, int srnr, int disk);
static void srpr_sm3c_act(void *rpm, int srnr, int disk);
static void srpr_sm4c_act(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_smi_pas(void *rpm, float v, int srnr, float sinaz, float cosaz, int disk)
@brief dummy instead of pr_vm1-4s/c_act
@param rpm (void *) Properly structured ringparms struct
@param sbr (float *) Original surface brightness on input, will not be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_smi_pas(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_sm0b_pas(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
@brief dummy instead of pr_sm0b_act(), replaces *sbr with 0.0
@param rpm (void *) Properly structured ringparms struct
@param sbr (float *) Original surface brightness on input, will not be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_sm0b_pas(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_sm1s_act(ringparms *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
@brief calculates s1 component and adds it to the input
@param rpm (ringparms *) Properly structured ringparms struct
@param sbr (float *) Original surface brightness on input, will be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_sm0b_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm1s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm2s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm3s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm4s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm1c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm2c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm3c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
static void pr_sm4c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void smi_sbrmax_act(void *rpm, int srnr, int disk)
@brief calculates the sum of absolute amplitudes of surface brightness modes and puts that number in the sbrmax variable of the subring structure
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void smi_sbrmax_act(void *rpm, int srnr, int disk);
static void smi_sbrmax_pas(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void smi_getaz_harm(void *rpm, float *az, float *cosaz, float *sinaz, int *signum, int srnr, int disk)
@brief returns an azimuth
If harmonics in the surface brightness are used, then the
distribution of point sources is not uniform. The function will take
care of a correct distribution of point sources returned.
@param rpm (void *) Properly structured ringparms struct, casted to void
@param cosaz (float *) Output: azimuth
@param cosaz (float *) Output: cosine of azimuth
@param sinaz (float *) Output: sine of azimuth
@param signum (int *) Output: signum of point source flux
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void smi_getaz_harm(void *rpm, float *az, float *cosaz, float *sinaz, int *signum, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void smi_getaz_cons(void *rpm, float *az, float *cosaz, float *sinaz, int *signum, int srnr, int disk)
@brief returns an azimuth
Returns new azimuth of point source, without harmics
@param rpm (void *) Properly structured ringparms struct, casted to void
@param az (float *) Output: azimuth
@param cosaz (float *) Output: cosine of azimuth
@param sinaz (float *) Output: sine of azimuth
@param signum (int *) Output: signum of point source flux
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void smi_getaz_cons(void *rpm, float *az, float *cosaz, float *sinaz, int *signum, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void smi_getcloudnumber_harm(ringparms *rpm, int srnr, int disk)
@brief returns a cloud number solving an integral
If harmonics in the surface brightness are used, then the
distribution of point sources is not uniform. In the case of
negative clouds, this function needs to be invoked to determine the
cloud number instead of the much simpler smi_getcloudnumber_norm
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void smi_getcloudnumber_harm(void *rpm, int srnr, int disk);
static void smi_getcloudnumber_norm(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void rndmf_init_sdis_pas(ringparms *rpm, int srnr, int disk)
@brief Initialises the rng internal to the calulation of sdis
@param rpm (void *) properly allocated ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void rndmf_init_smi_act(void *rpm, int srnr, int disk);
static void rndmf_init_smi_pas(void *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_gau_act(ringparms *rpm, int srnr, int number, int disk)
@brief calculates surface brightness Gaussian dispersion in rad and adds it to the ring
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param number (int) number of Gaussian component
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_gau_act(void *rpm, int srnr, int number, int disk);
static void srpr_gau_pas(void *rpm, int srnr, int number, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srpr_azi_act(ringparms *rpm, int srnr, int number, int disk)
@brief calculates ranges for the exclusion from the model
@param rpm (ringparms *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param number (int) number of segment
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void srpr_azi_act(void *rpm, int srnr, int number, int disk);
static void srpr_azi_pas(void *rpm, int srnr, int number, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void setoutrange_azi_act(int *outofrange)
@brief sets outofrange to 1
@param outofrnage (int *) Output: outofrange changes to 1
@return void
*/
/* ------------------------------------------------------------ */
static void setoutrange_azi_act(int *outofrange);
static void setoutrange_azi_pas(int *outofrange);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_azi_act(float *azi, float ranges[2][4], int *outofrange, int i)
@brief calculates ranges for the exclusion from the model
@param azi (float *) Azimuth
@param ranges (float[2][4]) the ranges to check (these are 8 ranges)
@param outofrnage (int *) Output: outofrange changes to 0 if the azimuth is in the range defined by ranges
@param i (int) Sub-range to check 0 or 1
@return void
*/
/* ------------------------------------------------------------ */
static void pr_azi_act(float *azi, float ranges[2][4], int *outofrange, int i);
static void pr_azi_pas(float *azi, float ranges[2][4], int *outofrange, int i);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srshape_azi_act(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk)
@brief Shape the point source
Changes the coordinates of the pointsource using srshape, if
outofrange == 0, if outofrange == 1, pp[0] = -1 and nothing is done
except for stepping forward in the rngs. The passive version only
calls srshape.
@param rpm (void *) Properly structured ringparms struct
@param pp (float *) Output: position of point source
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param srnr (int) sub-ring number
@param outofrnage (int *) outofrange 0 means do a normal shaping, 1 means do "nothing"
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static int srshape_azi_act(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk);
static int srshape_azi_pas(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void srshape_azi_act(void *rpm, int srnr, int outofrange, int signum)
@brief Shape the point source
Changes the coordinates of the pointsource using srshape, if
outofrange == 0, if outofrange == 1, pp[0] = -1 and nothing is done
except for stepping forward in the rngs. The passive version only
calls srshape.
@param rpm (void *) Properly structured ringparms struct
@param srnr (int) sub-ring number
@param outofrange (int) outofrange 0 means do a normal shaping, 1 means do "nothing"
@param signum (int) Dummy probably
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void corrp_azi_act(void *rpm, int srnr, int *outofrange, int signum);
static void corrp_azi_pas(void *rpm, int srnr, int *outofrange, int signum);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_wmi_pas(void *rpm, float v, int srnr, float sinaz, float cosaz, int disk)
@brief dummy instead of pr_vm1-4s/c_act
@param rpm (void *) Properly structured ringparms struct
@param z (float *) Original heigt on input, will be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_wmi_pas(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_wm0_act(ringparms *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
@brief calculates m0 component and adds it to the input
@param rpm (void *) Properly structured ringparms struct
@param z (float *) Original height above plane, will be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_wm0_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm1s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm2s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm3s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm4s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm1c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm2c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm3c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
static void pr_wm4c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_ls0_pas(void *rpm, float *x, int srnr, float sinaz, float cosaz, int disk)
@brief dummy instead of pr_ls0_act
@param rpm (void *) Properly structured ringparms struct
@param x (float *) Original height above plane, will be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_ls0_pas(void *rpm, float *x, int srnr, float sinaz, float cosaz, int disk);
static void pr_lc0_pas(void *rpm, float *x, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_ws1_act(ringparms *rpm, float *x, int srnr, float sinaz, float cosaz, int disk)
@brief calculates shift component and adds it to the input
@param rpm (void *) Properly structured ringparms struct
@param x (float *) Original height above plane, will be changed
@param srnr (int) sub-ring number
@param sinaz (float) sine of the azimuth
@param cosaz (float) cosine of the azimuth
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_ls0_act(void *rpm, float *x, int srnr, float sinaz, float cosaz, int disk);
static void pr_lc0_act(void *rpm, float *x, int srnr, float sinaz, float cosaz, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void pr_sdis_pas(void *rpm, float v, int srnr, int disk)
@brief dummy instead of pr_sdis_act
@param rpm (void *) Properly structured ringparms struct
@param v (float *) Original velocity on input, will be changed
@param vold (float *) Output: original velocity on input
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void pr_sdis_pas(void *rpm, float *v, float *vold, int srnr, int disk);
static void pr_vrad_pas(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk);
/* Note that the whole 6d point must be passed */
static void pr_vver_pas(void *rpm, float *point, int srnr, int disk);
static void pr_dvro_pas(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk);
static void pr_dvra_pas(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk);
static void pr_dvve_pas(void *rpm, float *point, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int activateftstab(startinf *startinfv, loginf *log, ringparms *rpm)
@brief Starts up the ftstab machinery
This sets up the ftstab module to work writing to (or appending to
the existent) the logfile. It sets the logfile -> logpres parameter
to 0 if the logfile is present, to 1 otherwise. An error is returned
if the user interrupts the progress, the logfile is not a fits
table, or if a logfile has been requested, but couldn't be
opened. If no logfile is requested, no error is returned
@param log (loginf *) Properly structured loginf struct
@param rpm (ringparms *) Properly allocated ringparms struct
@return int activateftstab: 0 (success)
>0 (error)
*/
/* ------------------------------------------------------------ */
static int activateftstab(startinf *startinfv, loginf *log, ringparms *rpm);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int int tir_get_grid(loginf *log, ringparms *rpm, double *array)
@brief Copy log -> grid to array
The arrays must have a dimension of nur*NPARAMS+nur*NDPARAMS+5
@param log (loginf *) Properly structured loginf struct
@param rpm (ringparms *) Properly structured ringparms struct
@param array (double *) Array of dimension nur*NPARAMS+nur*NDPARAMS+5
@return int tir_get_grid: 0 (success)
>0 (error)
*/
/* ------------------------------------------------------------ */
static int tir_get_grid(loginf *log, ringparms *rpm, double *array);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double tir_get_colgrid(loginf *log, ringparms *rpm, int i)
@brief Returns log -> grid[i-1]
The arrays must have a dimension of nur*NPARAMS+nur*NDPARAMS+5
@param log (loginf *) Properly structured loginf struct
@param rpm (ringparms *) Properly structured ringparms struct
@param i (int *) column number, starting at 1
@return double tir_get_colgrid
*/
/* ------------------------------------------------------------ */
static double tir_get_colgrd(loginf *log, ringparms *rpm, int i);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double tir_get_colrad(loginf *log, ringparms *rpm, int i)
@brief Returns log -> radius[i-1]
The arrays must have a dimension of nur*NPARAMS+nur*NDPARAMS+5
@param log (loginf *) Properly structured loginf struct
@param rpm (ringparms *) Properly structured ringparms struct
@param i (int *) column number, starting at 1
@return double tir_get_colrad
*/
/* ------------------------------------------------------------ */
static double tir_get_colrad(loginf *log, ringparms *rpm, int i);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int int tir_get_radius(loginf *log, ringparms *rpm, double *array)
@brief Copy log -> radius to array
The arrays must have a dimension of nur*NPARAMS+nur*NDPARAMS+5
@param log (loginf *) Properly structured loginf struct
@param rpm (ringparms *) Properly structured ringparms struct
@param array (double *) Array of dimension nur*NPARAMS+nur*NDPARAMS+5
@return int tir_get_radius: 0 (success)
>0 (error)
*/
/* ------------------------------------------------------------ */
static int tir_get_radius(loginf *log, ringparms *rpm, double *array);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int int tir_put_register(loginf *log, ringparms *rpm, double *array)
@brief Copy array to log -> regist
The arrays must have a dimension of nur*NPARAMS+nur*NDPARAMS+5
@param log (loginf *) Properly structured loginf struct
@param rpm (ringparms *) Properly structured ringparms struct
@param array (double *) Array of dimension nur*NPARAMS+nur*NDPARAMS+5
@return int tir_get_radius: 0 (success)
>0 (error)
*/
/* ------------------------------------------------------------ */
static int tir_put_register(loginf *log, ringparms *rpm, double *array);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int int tir_get_register(loginf *log, ringparms *rpm, double *array)
@brief Copy log -> regist to array
The arrays must have a dimension of nur*NPARAMS+nur*NDPARAMS+5
@param log (loginf *) Properly structured loginf struct
@param rpm (ringparms *) Properly structured ringparms struct
@param array (double *) Array of dimension nur*NPARAMS+nur*NDPARAMS+5
@return int tir_get_radius: 0 (success)
>0 (error)
*/
/* ------------------------------------------------------------ */
static int tir_get_register(loginf *log, ringparms *rpm, double *array);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int tir_fillhd(loginf *log, int i, double radius, double grid)
@brief Fill the i-1 th position of log -> grid and log -> radius with grid and radius
@param log (loginf *) Properly structured loginf struct
@param i (int) Properly structured ringparms struct
@param radius (double) Array of dimension nur*NPARAMS+nur*NDPARAMS+5
@param grid (double) Array of dimension nur*NPARAMS+nur*NDPARAMS+5
@return int tir_get_radius: 0 (success)
>0 (error)
*/
/* ------------------------------------------------------------ */
static int tir_fillhd(loginf *log, int i, double radius, double grid);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int dec_fill(ringparms *rpm, decomp_control *decomp_controlv)
@brief Fill a simparse decomp struct with parameter information
@param rpm (ringparms) properly configured ringparms struct
@param decomp_controlv (decomp_control *) Allocated simparse decomp control structure
@return 0: success
1: memory problems
*/
/* ------------------------------------------------------------ */
static int dec_fill(ringparms *rpm, decomp_control *decomp_controlv);
#ifdef PBCORR
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void alloc_pbcfac_act(ringparms *rpm, int srnr, int disk)
@brief Allocate memory for primary beam factors
same function pas doesn't do anything.
@param rpm (ringparms *) properly allocated ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void alloc_pbcfac_act(ringparms *rpm, int srnr, int disk);
static void alloc_pbcfac_pas(ringparms *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void dealloc_pbcfac_act(ringparms *rpm, int srnr, int disk)
@brief Deallocate memory for primary beam factors
same function pas doesn't do anything.
@param rpm (ringparms *) properly allocated ringparms struct
@param srnr (int) sub-ring number
@param disk (int) disk number
@return void
*/
/* ------------------------------------------------------------ */
static void dealloc_pbcfac_act(ringparms *rpm, int srnr, int disk);
static void dealloc_pbcfac_pas(ringparms *rpm, int srnr, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void fill_pbcfac_act((ringparms *rpm, struct srd **sd, int disk, int srnr, long *pnr, int *grid)
@brief Fill the pbfac array with the right numbers
same function pas doesn't do anything.
@param hdr (hdrinf *) properly allocated headerinf struct
@param sd (struct srd *[ndisks]) sub-ring array
@param disk (int) disk number
@param srnr (int) sub-ring number
@param pnr (long *) point number
@param grid (int *) grid position
@return void
*/
/* ------------------------------------------------------------ */
static void fill_pbcfac_act(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid);
static void fill_pbcfac_pas(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void corr_pbcfac_act(struct srd **sd, int disk, int srnr, long pnr)
@brief Apply the pbfac array with the right numbers
same function pas doesn't do anything.
@param sd (struct srd **) sub-ring array
@param disk (int) disk number
@param srnr (int) sub-ring number
@param pnr (long) point number
@return void
*/
/* ------------------------------------------------------------ */
/* static void corr_pbcfac_act(struct srd *sd[ndisks], int disk, int srnr, long pnr); */
/* static void corr_pbcfac_pas(struct srd *sd[ndisks], int disk, int srnr, long pnr); */
static void corr_pbcfac_act(struct srd **sd, int disk, int srnr, long pnr);
static void corr_pbcfac_pas(struct srd **sd, int disk, int srnr, long pnr);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static void chkb_pbcorr(hdrinf *hdr, ringparms *rpm)
@brief Link correct funtions for bpcorr
same function pas doesn't do anything.
@param hdr (hdrinf *) correctly allocated hdrinf struct
@param rpm (ringparms *) correctly allocated ringparms struct
@return void
*/
/* ------------------------------------------------------------ */
static void chkb_pbcorr(hdrinf *hdr, ringparms *rpm);
#endif
/*************/
/* Addendums under construction */
/*************/
/* #include "constr.h" */
/*************/
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static reg_cont *reg_cont_const(int nregs)
@brief Constructs a NULL-terminated array of n (empty) reg_containers
Constructs a NULL-terminated array of n (empty) reg_containers. The fc members are allocated.
@param nregs (int) number of single fc_containers
@return (success) reg_cont *reg_cont_const Allocated array of reg_containers
(error) NULL
*/
/* ------------------------------------------------------------ */
static reg_cont **reg_cont_const(int nregs);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static int reg_cont_destr(reg_cont **reg_contv)
@brief Constructs a NULL-terminated array of n (empty) reg_containers
Destructor of an array of pointers to regularisation containers as constructed with reg_cont_const().
@param reg_contv (reg_cont) regularisaton container to be destroyed.
@return (success) reg_cont *reg_cont_const Allocated array of reg_containers
(error) NULL
*/
/* ------------------------------------------------------------ */
static int reg_cont_destr(reg_cont **reg_contv);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static reg_cont **reg_cont_get(startinf *startinfv, ringparms *rpm, fitparms *fit)
@brief Get the regularisation list from user input
Reads in the regularisation information from the input.
@param startinfv (startinf *) A start descriptor struct, properly filled.
@param rpm (ringparms *) A ring parameter descriptor struct, properly filled.
@param fit (fitparms *) A fit parameter descriptor struct, properly filled.
@return (success) reg_cont **reg_cont_get regularisation struct
(error) 1: NULL memory problems
*/
/* ------------------------------------------------------------ */
static reg_cont **reg_cont_get(startinf *startinfv, hdrinf *hdr, ringparms *rpm, fitparms *fit);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/**
@fn static double reg_do(reg_cont **reg_contv, int loop, double chisquare)
@brief Change the chisquare penalising Fourier modes
For each entry in the reg_contv list, the vector reg_contv[i] ->
first that has been specified on input with the function
reg_cont_get() will be read as an input vector into reg_contv[i] ->
fc to then determine the ratio of the modes specified on
input. This is done in the following way (see fourat.h):
i) the input array is interpolated (or extrapolated) between the active elements as
specified in REGPARA=.
ii) The interpolated array is Fourier-transformed.
iii) The amplitudes of the orders specified in numerator (REGNUME=) are summed
and divided by the sum of the amplitudes of the orders specified in
denominator (REGDENO=), or, if greater than zero, by the amplitudes specified in REGAMPD=, the ratio being r.
iv) r is used to determine an addition to the chisquare >= 0, following a smooth step
determined by regthre (REGTHRE= threshold above which the result is
> 1), regwidt (REGWIDT=, width of step, the maximum is reached if r
= regthre+regwidt), regampl (REGAMPL=, amplitude of step in first
loop), and regaste (REGASTE=, each loop the step amplitude is
increased by this value).
v) The factors for each regularised groups are added to 1 (, stored, ) and returned.
@param reg_contv (reg_cont **) A NULL-terminated list of regularisation structs
@param loop (int) Loop number
@param chisquare (double) Input chisquare
@return double reg_do: Product of ratios of modes
*/
/* ------------------------------------------------------------ */
static double reg_do(reg_cont **reg_contv, int loop, double chisquare);
static int writecoolmodel(startinf *startinfv, loginf *log, hdrinf *origin, ringparms *rpm, fitparms *fit, double *par, decomp_inlist *index);
static int galmodcool(hdrinf *hdr, ringparms *rpm, int fitmode, varlel *varele, decomp_inlist *index, long *fluxpoints, int *allnpoints);
static long srconstcool(hdrinf *hdr, ringparms *rpm, int srnr, long mode, int disk);
static int srshape_azi_pascool(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk);
static int srshape_azi_actcool(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk);
static void srshapecool(ringparms *rpm, float *pp, float sinaz, float cosaz, int srnr, int disk);
#ifdef PBCORR
static void gridpoint_mixedcool(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#else
static void gridpoint_mixedcool(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#endif
#ifdef PBCORR
static void gridpoint_normcool(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#else
static void gridpoint_normcool(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk);
#endif
static void sdis_repeater_actcool(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk);
static void sdis_repeater_pascool(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk);
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* FUNCTION CODE */
/* ------------------------------------------------------------ */
int main(int argc, char *argv[])
{
startinf *startinfv = NULL;
loginf *log = NULL;
hdrinf *hdr = NULL;
ringparms *rpm = NULL;
fitparms *fit = NULL;
int i = 0;
int j;
int nrplts;
char mes[81];
printf("\n");
printf("#####################\n");
printf("# TiRiFiC v. 2.3.11 #\n");
printf("#####################\n");
printf("\n");
if (!(startinfv = get_startinf(argc, argv)))
goto error;
while (check_restart(startinfv, hdr, rpm, log)) {
if (!(log = get_loginf(startinfv, log)))
goto error;
if (!(hdr = get_hdrinf(startinfv, log, hdr)))
goto error;
if (!(rpm = get_ringparms(startinfv, log, hdr, rpm)))
goto error;
if (!(fit = get_fitparms(startinfv, log, hdr, rpm, fit))) {
goto error;
}
if ((j = open_hdu_3(log, hdr, rpm, fit)) == 1) {
goto error;
}
/* else if (j == 2) */
/* ; */
/* else if (j == 0) */
prepout(log, hdr, rpm);
if (fit -> fitmode == METROPOLIS) {
/* if (!metropolis(log, hdr, rpm, fit)) { */
/* goto error; */
/* } */
/* if (!putmetresults(log, rpm, fit)) { */
/* goto error; */
/* } */
;
}
else if (fit -> fitmode == GOLDEN_SECTION) {
if (!golden_section(startinfv, log, hdr, rpm, fit))
goto error;
if (!putgoldresults(log, rpm, fit))
goto error;
}
else if (fit -> fitmode > GOLDEN_SECTION) {
if (!genfit(startinfv, log, hdr, rpm, fit))
goto error;
if (!putgenresults(startinfv, log, hdr, rpm, fit))
goto error;
}
/* put the results in an ascii table */
writeasctable(startinfv, log, hdr, rpm, fit);
/* Put the results for each subring in an ascii table */
writebigasctable(startinfv, log, hdr, rpm, fit);
/* Graphics */
nrplts = graphout(startinfv, log, hdr, rpm, fit);
nrplts = ((nrplts))?nrplts:1;
briggsout(startinfv, log, hdr, rpm, fit);
/* Output of a def file */
tirout(startinfv, log, rpm, fit, nrplts);
/* Output of a histogram */
/* histout(rpm); */
/* Rectify output */
/* rectout(log, hdr, rpm, fit); */
/* Tiltogram output */
tiltout(startinfv, log, hdr, rpm, fit);
/* Write the output cube */
i = 1;
if ((*hdr -> outset != '\0')) {
/* We read all values into the par array */
tir_get_grid(log, rpm, log -> outarray);
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i)
rpm -> oldpar[i] = log -> outarray[i];
changetointern(rpm -> oldpar, rpm -> nur, hdr, rpm -> ndisks);
/* Now we write it */
writemodel(hdr, rpm, fit, rpm -> oldpar, fit -> index);
}
/* Renzo */
renzo(startinfv, log, hdr, rpm);
/* Cool */
coolgal(startinfv, log, hdr, rpm, fit);
/* Cool again */
writecoolmodel(startinfv, log, hdr, rpm, fit, rpm -> oldpar, fit -> index);
if ((log -> tstream))
fclose(log -> tstream);
log -> tstream = NULL;
/* Close the progress file, Kamphuis addition */
progressfinished(startinfv);
loop_restart(startinfv);
}
/* if ((*hdr -> outset != '\0')) */
/* gds_close_tir(hdr -> outset, &i); */
/* ftstab_putminmax_(); */
ftstab_close_();
ftstab_flush_();
ftstab_hdlreset_();
hdl_init(rpm -> ndisks);
destroy_startinf(startinfv);
destroy_loginf(log, rpm -> ndisks);
destroy_hdrinf(hdr);
destroy_fitparms(fit);
destroy_ringparms(rpm);
/* finis_c(); */
/* fprintf(stderr,"Got here: end\n");*/
return 1;
error:
i = 0;
sprintf(mes, "ABORTING: Memory problems, unwise parameters, user abort");
anyout_tir(&i, mes);
if ((log))
destroy_loginf(log, rpm -> ndisks);
if ((hdr))
destroy_hdrinf(hdr);
if ((rpm))
destroy_ringparms(rpm);
if ((fit))
destroy_fitparms(fit);
ftstab_close_();
ftstab_flush_();
/* finis_c(); */
return 0;
}
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns a gipsy compatible char array */
static int tir_get_grid(loginf *log, ringparms *rpm, double *array)
{
int i;
for (i = 0; i < (rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS+OUTTABNR); ++i)
array[i] = log -> grid[i];
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns a gipsy compatible char array */
static double tir_get_colgrd(loginf *log, ringparms *rpm, int i)
{
return log -> grid[i-1];
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns a gipsy compatible char array */
static double tir_get_colrad(loginf *log, ringparms *rpm, int i)
{
return log -> radius[i-1];
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* */
static int tir_get_radius(loginf *log, ringparms *rpm, double *array)
{
int i;
for (i = 0; i < (rpm -> nur*(NPARAMS+(rpm -> ndisks -1)*NDPARAMS)+NSPARAMS+OUTTABNR); ++i)
array[i] = log -> radius[i];
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* */
static int tir_get_register(loginf *log, ringparms *rpm, double *array)
{
int i;
for (i = 0; i < (rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS+OUTTABNR); ++i)
array[i] = log -> regist[i];
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* */
static int tir_put_register(loginf *log, ringparms *rpm, double *array)
{
int i;
for (i = 0; i < (rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS+OUTTABNR); ++i)
log -> regist[i] = array[i];
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns a gipsy compatible char array */
static int tir_fillhd(loginf *log, int i, double radius, double grid)
{
log -> grid[i] = grid;
log -> radius[i] = radius;
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* testing ftstab */
static int activateftstab(startinf *startinfv, loginf *log, ringparms *rpm)
{
int def;
char mes[101];
char mon_key[20];
char value[20];
int anint = 0;
int logfile_present = 0;
int logfile_faulty = 0;
int logfile_not_tir = 0;
int nel = 1;
/* If there is no logfile specified we simply terminate the logname */
if (*log -> logname == '\0') {
free(log -> logname);
log -> logname = NULL;
}
log -> logpres = 1;
/* Close and reopen ftstab */
if (!startinfv -> firstrun)
ftstab_close_();
/* initialise */
/* Initialise the table content object */
ftstab_flush_();
/* Virginalise the header information table */
ftstab_hdlreset_();
/* Initialising the logfile info: change */
/* This defines possible table items, their numbers (PPARAM+1),
type, unit, scaling, it does not create a table */
hdl_init(rpm -> ndisks);
if ((log -> logname)) {
/* Check if the logfile already exists and tell the user if yes */
if (!(rename(log -> logname, log -> logname))) {
sprintf(mes, "LOGFILE present");
anyout_tir(&anint,mes);
logfile_present = 1;
}
if (!startinfv -> firstrun){
sprintf(mes, "multiple runs, will overwrite LOGFILE");
anyout_tir(&anint,mes);
logfile_present = 1;
}
/* open */
/* returns 0 if file is present and could not be opened, 2 if no file is present and could also not be opened, something else if there is an error. (name,
extension, mode (2: append), extension, history header, don't
care.) Have to admit that this is a bit obscure, so I hope it still works.*/
log -> logpres = ftstab_fopen(log -> logname, 1, 2, 1);
/* An error occured connected to the opening of the logfile, inform the user */
if (log -> logpres && (log -> logpres != 2)) {
sprintf(mes, "LOGFILE faulty");
anyout_tir(&anint,mes);
logfile_faulty = 1;
}
if (!(log -> logpres)) {
sprintf(mon_key, "CREATOR");
if (ftstab_getcard(0, mon_key, value, 1)) {
if (strcmp(value, "'TIRIFIC '")){
logfile_not_tir = 1;
}
}
else
logfile_not_tir = 1;
if (logfile_not_tir) {
sprintf(mes, "LOGFILE not created by TiRiFiC");
anyout_tir(&anint,mes);
}
}
/* Ask what to do (only if this is a single run) */
if ((logfile_present)) {
if (startinfv -> firstrun) {
sprintf(mes, "continue [0]");
anyout_tir(&anint,mes);
sprintf(mes, "delete logfile and continue [1]");
anyout_tir(&anint,mes);
sprintf(mes, "stop [everything else, e.g. 2]");
anyout_tir(&anint,mes);
def = 1;
nel = 1;
anint = 0;
sprintf(mes, "0, 1, or 2 [0]?");
userint_tir(startinfv -> arel, &anint, &nel, &def, "ACTION", mes);
/* fprintf("", startinf -> arel -> keyvallipre -> key); */
/* We proceed and at the moment reset PROCEED */
/* cancel_tir(startinfv -> arel, "ACTION=", 0); */
}
else {
anint = 1;
}
if (anint) {
if (anint == 1) {
/* Close the file, delete it, and open it again */
ftstab_close_();
ftstab_flush_();
ftstab_hdlreset_();
hdl_init(rpm -> ndisks);
remove(log -> logname);
log -> logpres = ftstab_fopen(log -> logname, 1, 2, 1);
}
else {
/* Close the file, and stop */
ftstab_close_();
ftstab_flush_();
ftstab_hdlreset_();
hdl_init(rpm -> ndisks);
log -> logpres = 1;
goto error;
}
}
/* If the logfile was faulty, we close anyway */
else if (logfile_faulty) {
ftstab_close_();
ftstab_flush_();
ftstab_hdlreset_();
hdl_init(rpm -> ndisks);
log -> logpres = 1;
sprintf(mes, "LOGFILE faulty, this never works.");
anyout_tir(&anint,mes);
goto error;
}
}
/* I think the following should only be done if a file is not present, in which case the answer is 2 */
if (log -> logpres == 2) {
/* create a column, check what happens if there is already a table
object, success is 1, not 0 (verra old code) */
ftstab_inithd(1L);
/* now fill the column with information, columns start at 0 */
/* output = ftstab_fillhd(0L, NPARAMS+(rpm -> ndisks-1)*NDPARAMS+NSPARAMS+PRIMHDN_SINGLE+SECHDN_MULTI+CHISQ_TABNR, COLTYPE_DOUBLE, 0.0, -1.0); */
ftstab_fillhd(0L, NPARAMS+(rpm -> ndisks-1)*NDPARAMS+NSPARAMS+(LASTSING_PRIMPOS+NUMB_MDPRIMPOS*rpm -> ndisks)+SECHDN_MULTI+CHISQ_TABNR, COLTYPE_DOUBLE, 0.0, -1.0);
}
/* Now open the file and put some text there (or vice versa) */
if (log -> logpres) {
ftstab_genhd(0);
/* probably the only thing that we'll do */
sprintf(mon_key, "CREATOR");
sprintf(value, "TIRIFIC");
ftstab_putcard(0, mon_key, value);
if ((log -> logpres = ftstab_fopen(log -> logname, 1, 2, 1))) {
goto error;
}
}
}
/* Logfile is open or not present */
return 0;
error:
/* Whenever we got here, there was an error, such that we should stop. Logfile is closed */
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a startinf structure */
static startinf *create_startinf(void)
{
startinf *startinfv;
/* Allocate the struct */
if (!(startinfv = (startinf *) malloc(sizeof(startinf))))
return NULL;
/* First set all pointers to 0 and initialise some pointers */
startinfv -> arel = NULL;
startinfv -> restartname = NULL;
startinfv -> restartid = 0;
startinfv -> firstrun = 1;
/* if (!(startinfv -> restartname = getfcharray(200, NULL))) */
/* goto error; */
if (!((startinfv -> filestat) = (struct stat *) malloc(sizeof(struct stat)))) {
goto error;
}
return startinfv;
error:
destroy_startinf(startinfv);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Destroys a loginf structure */
static void destroy_startinf(startinf *startinfv)
{
/* Make it safer against unwarranted use */
if (!(startinfv))
return;
/* Deallocate */
if ((startinfv -> arel)) {
simparse_scn_arellist_dest(startinfv -> arel);
}
if (startinfv -> restartname) {
free(startinfv -> restartname);
}
if (startinfv -> filestat) {
free(startinfv -> filestat);
}
free(startinfv);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Initialisation of the program concerning info from the dataset */
static startinf *get_startinf(int argc, char **argv)
{
startinf *startinfv;
/* char mes[81]; */
/* int def, nel; */
int i, blen, blin;
char *buffer = NULL;
int nread, nreturned;
char *returnedc;
int *prompt = NULL, *restartid = NULL;
int restartdef = 0;
int promptdef = 0;
int keypres;
char **varystr = NULL;
/* Try to allocate */
if (!(startinfv = create_startinf()))
goto error;
/* Get the command line into a buffer */
/* first count */
blen = 0;
for (i = 1; i < argc; ++i) {
blen = blen + strlen(argv[i]) + 1;
}
++blen;
/* Then allocate */
if (!(buffer = (char *) malloc(blen*sizeof(char))))
goto error;
/* Then fill */
if (argc == 1) {
buffer[0] = '\0';
}
blen = 0;
for (i = 1; i < argc; ++i) {
memcpy(buffer+blen, argv[i], blin = strlen(argv[i]));
blen = blen + blin;
if (i < (argc - 1))
buffer[blen] = ' ';
else
buffer[blen] = '\0';
++blen;
}
/* Now get the key struct */
if (!(startinfv -> arel = simparse_scn_arel_insert(NULL, "Command line", buffer, NULL)))
goto error;
/* An input of restartid != 0 on the command line is an error */
if (simparse_scn_arel_readval_int(startinfv -> arel, "RESTARTID", "ID of restart process [0]", 1, &restartdef, 1, 1, 0, 0, &keypres, &nread, &nreturned, &restartid))
goto error;
if (*restartid) {
fprintf(stderr, "Error: cannot define RESTARTID=%i, other than RESTARTID=0 on command line.\n(Would lead to an endless loop.)\n", *restartid);
goto error;
}
free(restartid);
/* Read out the file name */
if (simparse_scn_arel_readval_string(startinfv -> arel, "DEFFILE", "Provide default file name (default: no file).", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &returnedc))
goto error;
if ((returnedc[0]))
printf("Using default file with name: %s\n", returnedc);
if (!(startinfv -> arel = simparse_scn_arel_insert(startinfv -> arel, NULL, NULL, returnedc)))
goto error;
free(returnedc);
/* Check if prompting */
if (simparse_scn_arel_readval_int(startinfv -> arel, "PROMPT", "Prompt on error or terminate on error (prompt: 1, terminate: 0)? [0]", 1, &promptdef, 1, 1, 0, 0, &keypres, &nread, &nreturned, &prompt))
goto error;
/* Switch prompting on or off */
simparse_scn_arel_onerror_prompt(startinfv -> arel, *prompt);
if ((*prompt))
printf("Will prompt on error.\n");
else
printf("Will terminate on error.\n");
free(prompt);
/* The startfile */
/* cancel_tir(startinfv -> arel, "RESTARTNAME"); */
if ((startinfv -> restartname)) {
free(startinfv -> restartname);
startinfv -> restartname = NULL;
}
if (varystr) {
freeparsed(varystr);
varystr = NULL;
}
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "RESTARTNAME", "Give restartfile name.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(startinfv -> restartname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(startinfv -> restartname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
if (simparse_scn_arel_readval_int(startinfv -> arel, "RESTARTID", "ID of restart process [0]", 1, &restartdef, 1, 1, 0, 0, &keypres, &nread, &nreturned, &restartid))
goto error;
startinfv -> restartid = *restartid;
/* The startfile */
/* sprintf(mes, "Give restartfile name."); */
/* for (i = 0; i < 200; ++i) */
/* startinfv -> restartname[i] = ' '; */
/* startinfv -> restartname[200] = '\0'; */
/* def = 2; */
/* nel = 1; */
/* userchar_tir(startinfv -> restartname, &nel, &def, "RESTARTNAME=", mes); */
/* termsinglestr(startinfv -> restartname); */
free(buffer);
free(restartid);
return startinfv;
error:
if ((startinfv)) {
/* Stop the logfile io, also put ndisks = 1, is irrelevant */
destroy_startinf(startinfv);
}
if ((buffer))
free(buffer);
if ((prompt))
free(prompt);
if ((startinfv -> arel))
simparse_scn_arellist_dest(startinfv -> arel);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Return 1 if restart, 0 else */
static int check_restart(startinf *startinfv, hdrinf *hdr, ringparms *rpm, loginf *log)
{
int retval,i;
if (strlen(startinfv -> restartname)) {
/* Check if file information can be acquired and fill stuff */
if (stat(startinfv -> restartname, startinfv -> filestat)) {
retval = 0;
}
else {
startinfv -> timestamp = startinfv -> filestat -> st_mtime;
retval = 1;
}
}
else {
retval = 0;
}
if (startinfv -> firstrun)
retval = 1;
if ((retval)) {
if ((rpm)) {
/* We read all values into the par array and to be sure make oldpar and par equal */
tir_get_grid(log, rpm, log -> outarray);
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i)
rpm -> oldpar[i] = log -> outarray[i];
changetointern(rpm -> oldpar, rpm -> nur, hdr, rpm -> ndisks);
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i)
rpm -> par[i] = rpm -> oldpar[i];
}
}
return retval;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Check if restartfile exists and loop until its last change time stamp has changed with respect to the value stored in startinfv, make some switches afterwards */
static int loop_restart(startinf *startinfv)
{
/* char mes[81]; */
/* int def, nel, i; */
char **varystr = NULL;
int *restartid = NULL;
int keypres, nread, nreturned;
simparse_scn_keyvalli **keyvallifile;
/* If the function is called, this should be done */
startinfv -> firstrun = 0;
/* Check if file is named */
if (strlen(startinfv -> restartname)) {
/* Check if file information can be acquired and fill stuff */
if (stat(startinfv -> restartname, startinfv -> filestat)) {
/* Notice that tirific will not wait until the restartfile is created */
return 0;
}
else {
fflush(NULL);
printf("Waiting for file %s to change", startinfv -> restartname);
if (startinfv -> restartid) {
/* GJnew */
/* if ((keyvallifile = simparse_scn_keyvallilist_gfrfi(startinfv -> arel[2] -> orifilename))) { */
printf(" and RESTARTID= %i to change in %s.\n", startinfv -> restartid, startinfv -> arel[2] -> orifilename);
/* } */
}
else {
printf(".\n");
}
/* Run a loop until the timestamps are the same or the file becomes unreadable */
while (startinfv -> timestamp >= startinfv -> filestat -> st_mtime) {
if (stat(startinfv -> restartname, startinfv -> filestat)) {
break;
}
}
printf("File %s has changed.", startinfv -> restartname);
/* Now refresh the input name and read it in again (not sure if this works or if the .def file has to be reread into some buffer before */
/* Changed this here */
cancel_tir(startinfv -> arel, "RESTARTNAME=", 1);
/* Just make sure that the file is re-read */
/* This may add an extra layer of security of sync */
do {
if ((restartid))
free(restartid);
if (startinfv -> arel && startinfv -> arel[1] && startinfv -> arel[2]) {
if ((keyvallifile = simparse_scn_keyvallilist_gfrfi(startinfv -> arel[2] -> orifilename))) {
simparse_scn_keyvallilist_dest(startinfv -> arel[2] -> keyvallifile);
startinfv -> arel[2] -> keyvallifile = keyvallifile;
}
else {
simparse_scn_arel_timestamp_early(startinfv -> arel[2]);
}
}
if (simparse_scn_arel_readval_int(startinfv -> arel, "RESTARTID=", "ID of restart process [0]", 1, &startinfv -> restartid, 1, 1, 0, 0, &keypres, &nread, &nreturned, &restartid))
goto error;
} while ((*restartid == startinfv -> restartid) && (startinfv -> restartid != 0));
startinfv -> restartid = *restartid;
if ((startinfv -> restartname)) {
free(startinfv -> restartname);
startinfv -> restartname = NULL;
}
/* sprintf(mes, "Give restartfile name."); */
/* for (i = 0; i < 200; ++i) */
/* startinfv -> restartname[i] = ' '; */
/* startinfv -> restartname[200] = '\0'; */
/* def = 4; */
/* nel = 1; */
/* userchar_tir(startinfv -> restartname, &nel, &def, "RESTARTNAME=", mes); */
/* termsinglestr(startinfv -> restartname); */
/* Let's do this by default */
if (varystr) {
freeparsed(varystr);
varystr = NULL;
}
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "RESTARTNAME", "Give name of file to restart.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(startinfv -> restartname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(startinfv -> restartname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* *** */
/* if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "BILLIBULLY", "Give name of file to restart.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr)) */
/* goto error; */
/* if ((varystr[0])) { */
/* fprintf(stderr,"bill: |%s|\n",varystr[0]); */
/* } */
/* freeparsed(varystr); */
/* varystr = NULL; */
/* fprintf(stderr, "RESTARTNAME: %s", startinfv -> restartname); */
/* *** */
}
}
else {
return 0;
}
if ((varystr)) {
freeparsed(varystr);
}
/* GJnew */
if ((restartid))
free(restartid);
return 0;
error:
if ((varystr)) {
freeparsed(varystr);
}
if ((restartid))
free(restartid);
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a loginf structure */
static loginf *create_loginf(void)
{
loginf *log;
/* Allocate the struct */
if (!(log = (loginf *) malloc(sizeof(loginf))))
return NULL;
/* First set all pointers to 0 and initialise some pointers */
log -> logname = NULL;
log -> logpres = 1;
log -> tstream = NULL;
log -> textlog = NULL;
/* Kamphuis addition */
log -> progresslog = NULL;
log -> table = NULL;
log -> outarray = NULL;
log -> grid = NULL;
log -> radius = NULL;
log -> regist = NULL;
log -> changes = 0;
/* Allocate and terminate */
/* if (!(log -> logname = getfcharray(200, NULL))) */
/* goto error; */
/* if (!(log -> textlog = getfcharray(200, NULL))) */
/* goto error; */
/* if (!(log -> progresslog = getfcharray(200, NULL))) */
/* goto error; */
/* if (!(log -> table = getfcharray(200, NULL))) */
/* goto error; */
log -> logname = NULL;
log -> textlog = NULL;
log -> progresslog = NULL;
log -> table = NULL;
return log;
/* error: */
/* Note: at this point, number of disks is unknown, but also irrelevant */
/* destroy_loginf(log, 1); */
/* return NULL; */
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Destroys a loginf structure */
static void destroy_loginf(loginf *log, int ndisks)
{
/* Make it safer against unwarranted use */
if (!(log))
return;
/* Deallocate */
if (log -> logname) {
free(log -> logname);
log -> logname = NULL;
if (!(log -> logpres)) {
ftstab_flush_();
ftstab_hdlreset_();
hdl_init(ndisks);
}
}
if (log -> textlog != NULL) {
free(log -> textlog);
log -> textlog = NULL;
}
/* Kamphuis addition */
if (log -> progresslog != NULL) {
free(log -> progresslog);
log -> progresslog = NULL;
}
if (log -> table != NULL) {
free(log -> table);
log -> table = NULL;
}
if (log -> grid != NULL) {
free(log -> grid);
log -> grid = NULL;
}
if (log -> radius != NULL) {
free(log -> radius);
log -> radius = NULL;
}
if (log -> regist != NULL) {
free(log -> regist);
log -> regist = NULL;
}
if (log -> outarray != NULL) {
free(log -> outarray);
log -> outarray = NULL;
}
free(log);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a hdrinf structure */
static hdrinf *create_hdrinf(void)
{
hdrinf *create_hdrinf;
/* Allocate the struct */
if (!(create_hdrinf = (hdrinf *) malloc(sizeof(hdrinf))))
return NULL;
/* First set all pointers to 0 */
create_hdrinf -> inset = NULL;
/* create_hdrinf -> insubs = NULL; */
/* create_hdrinf -> cwlo = NULL; */
/* create_hdrinf -> cwhi = NULL; */
/* create_hdrinf -> ori = NULL; */
create_hdrinf -> oric = NULL;
/* create_hdrinf -> model = NULL; */
create_hdrinf -> modelc = NULL;
create_hdrinf -> coolcube = NULL;
create_hdrinf -> outset = NULL;
create_hdrinf -> chi2 = DBL_MAX;
create_hdrinf -> oldchi2 = DBL_MAX;
#ifdef PBCORR
create_hdrinf -> primbeam = NULL;
#endif
/* Allocate and initialise the arrays */
/* Allocate inset, we allow for more than 18 characters */
/* if (!(create_hdrinf -> inset = getfcharray(200, NULL)))
goto error;*/
/* Allocate coordinate descriptor array */
/* GJnew: removed this, lead to leakage */
/* if (!(create_hdrinf -> insubs = (int *) malloc(MAXNSUBS*sizeof(int)))) */
/* goto error; */
/* Allocate outset, we allow for more than 18 characters */
/* if (!(create_hdrinf -> outset = getfcharray(200, NULL))) */
/* goto error; */
return create_hdrinf;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Destroys a hdrinf structure */
static void destroy_hdrinf(hdrinf *hdr)
{
/* Make it safer against unwarranted use */
if (!(hdr))
return;
if (hdr -> inset != NULL)
free(hdr -> inset);
/* if (hdr ->insubs != NULL) */
/* free(hdr -> insubs); */
/* if (hdr -> cwhi != NULL) */
/* free(hdr -> cwhi); */
/* if (hdr -> cwlo != NULL) */
/* free(hdr -> cwlo); */
if (hdr -> oric != NULL)
cubarithm_cube_destroy(hdr -> oric);
if (hdr -> modelc != NULL)
cubarithm_cube_destroy(hdr -> modelc);
if (hdr -> coolcube != NULL)
cubarithm_cube_destroy(hdr -> coolcube);
/* These are just the same as the points array in oric and modelc */
/* if (hdr -> ori != NULL) */
/* free_engalmod(hdr -> ori); */
/* if (hdr -> model != NULL) */
/* free_engalmod(hdr -> model); */
if (hdr -> outset != NULL)
free(hdr -> outset);
#ifdef PBCORR
if ((hdr -> primbeam))
free((hdr -> primbeam));
#endif
/* Deallocate the struct */
free(hdr);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Initialisation of the program concerning info from the dataset */
static loginf *get_loginf(startinf *startinfv, loginf *loginfv)
{
loginf *log;
char mes[81];
int def, nel;
int nread, nreturned, keypres;
/* There's two possibilities: this is the first pass, which means to create the loginf structure, or this is the second pass, in which case we don't do anything */
if (!startinfv -> firstrun)
return loginfv;
/* Try to allocate */
if (!(log = create_loginf()))
goto error;
#ifdef OPENMPTIR
/* The very first thing to do is to ask for the number of cores */
log -> ncores = 1;
def = 5;
sprintf(mes, "Give maximum number of cores. [1]");
nel = 1;
userint_tir(startinfv -> arel, &log -> ncores, &nel, &def, "NCORES=", mes);
while (log -> ncores < 1) {
sprintf(mes, "Should be at least one, eh?");
cancel_tir(startinfv -> arel, "NCORES=", 2);
userint_tir(startinfv -> arel, &log -> ncores, &nel, &def, "NCORES=", mes);
}
omp_set_num_threads(log -> ncores);
#else
log -> ncores = 1;
#endif
/* First thing to do is the logfile and the text logfile */
/* The logfile */
if (simparse_scn_arel_readval_string(startinfv -> arel, "LOGNAME", "Provide logfile name (default: no file).", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &(log -> logname)))
goto error;
/* sprintf(mes, "Give logfile name."); */
/* for (i = 0; i < 200; ++i) */
/* log -> logname[i] = ' '; */
/* log -> logname[200] = '\0'; */
/* Formerly def = 5 */
/* def = 5; */
/* nel = 1; */
/* userchar_tir(log -> logname, &nel, &def, "LOGNAME=", mes); */
/* This puts an \0 to the end of the text */
/* termsinglestr(log -> logname); */
/* The text logfile */
if (simparse_scn_arel_readval_string(startinfv -> arel, "TEXTLOG", "Provide text logfile name (default: no file).", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &(log -> textlog)))
goto error;
/* for (i = 0; i < 200; ++i) */
/* log -> textlog[i] = ' '; */
/* log -> textlog[200] = '\0'; */
/* def = 2; */
/* sprintf(mes, "Give text logfile name."); */
/* nel = 1; */
/* userchar_tir(log -> textlog, &nel, &def, "TEXTLOG=", mes); */
/* This puts an \n to the end of the text */
/* termsinglestr(log -> textlog); */
/* The Prgress LOG Kamphuis addition */
if (simparse_scn_arel_readval_string(startinfv -> arel, "PROGRESSLOG", "Provide progress logfile name (default: no file).", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &(log -> progresslog)))
goto error;
/* for (i = 0; i < 200; ++i) */
/* log -> progresslog[i] = ' '; */
/* log -> progresslog[200] = '\0'; */
/* def = 2; */
/* sprintf(mes, "Give progress logfile name."); */
/* nel = 1; */
/* userchar_tir(log -> progresslog, &nel, &def, "PROGRESSLOG=", mes); */
/* This puts an \n to the end of the text */
/* termsinglestr(log -> progresslog); */
/* Kamphuis addition end */
/* The result name */
if (simparse_scn_arel_readval_string(startinfv -> arel, "TABLE", "Give output table name (default: no file).", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &(log -> table)))
goto error;
/* for (i = 0; i < 200; ++i) */
/* log -> table[i] = ' '; */
/* log -> table[200] = '\0'; */
/* sprintf(mes, "Give output table name."); */
/* nel = 1; */
/* def = 2; */
/* userchar_tir(log -> table, &nel, &def, "TABLE=", mes); */
/* This puts an \0 to the end of the text */
/* termsinglestr(log -> table); */
/* Now get the distance of the object */
log -> distance = 10;
def = 2;
sprintf(mes,"Distance in Mpc [10]");
nel = 1;
userdble_tir(startinfv -> arel, &log -> distance, &nel, &def, "DISTANCE=", mes);
while (log -> distance <= 0) {
sprintf(mes,"DISTANCE must be greater than zero.");
log -> distance = 10;
cancel_tir(startinfv -> arel, "DISTANCE=", 2);
userdble_tir(startinfv -> arel, &log -> distance, &nel, &def, "DISTANCE=", mes);
}
return log;
error:
if ((log)) {
/* Stop the logfile io, also put ndisks = 1, is irrelevant */
destroy_loginf(log, 1);
}
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Initialisation of the program concerning info from the dataset */
static hdrinf *get_hdrinf(startinf *startinfv, loginf *log, hdrinf *hdrinfv)
{
hdrinf *hdr = NULL; /* The output */
int dev; /* Output device */
int def; /* Any default mode */
int nel; /* Number of elements */
int class; /* A class for the input of a set */
/* int classdim; */ /* Some other thing necessary for io of datasets */
/* int option; */ /* Input to gdsbox */
int err; /* Error code */
int outerr; /* Error heaviness for output */
/* int level; */ /* Strange level thingy */
char mes[81]; /* Any message */
/* char manual = 0; */ /* Signal for manual input */
/* char ciax[9]; */ /* Keyword holder */
/* char value[21]; */ /* Value holder */
/* int i,j; */ /* Control variable */
/* double deltsettouser[3]; */ /* Conversion factor from cuniti to userdeltunit */
/* double setcdelt[3]; */ /* The cdelts in the set */
/* double setcrval[3]; */ /* The reference values in the set */
/* double userdeltcdelt[3]; */ /* The cdelt in delta user units */
/* dummies */
/* int inaxcount[MAXNAX]; */
/* int outaxperm[MAXNAX]; */
/* int outaxcount[MAXNAX]; */
/* int outsubs[MAXNSUBS]; */
/* int blo[3]; */ /* Contains lower values for subset dimensions for 2 axes */
/* int bhi[3]; */ /* Contains higher values for subset dimensions for 2 axes */
/* double vardouble; */ /* Any double */
/* Just to pass pointers (FORTRAN ...) */
/* int maxnsubs = MAXNSUBS; */
/* int maxnax = MAXNAX; */
int nread, nreturned, keypres;
char errormes[120];
char **stringlist = NULL;
simparse_scn_arel *temparel;
/* Everything in the header will be read once and not multiple times */
if (!startinfv -> firstrun) {
if ((hdrinfv)) {
if ((hdrinfv -> outset)) {
free(hdrinfv -> outset);
hdrinfv -> outset = NULL;
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "OUTSET", "Give output cube name.", 0, NULL, 0, 1, 0, 0, &keypres, &nread, &nreturned, &stringlist))
goto error;
if ((stringlist[0])) {
if (!(hdrinfv -> outset = simparse_copystring(stringlist[0]))) {
goto error;
}
}
else {
if (!(hdrinfv -> outset = simparse_copystring("")))
goto error;
}
freeparsed(stringlist);
stringlist = NULL;
}
}
return hdrinfv;
}
if (!(hdr = create_hdrinf()))
goto error;
/* Get cube name */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "INSET", "Give input cube name (no default).", 0, NULL, 1, 1, 1, 0, &keypres, &nread, &nreturned, &stringlist))
goto error;
if (!(hdr -> inset = simparse_copystring(stringlist[0])))
goto error;
freeparsed(stringlist);
stringlist = NULL;
/* Read the cube */
/* This is a trick to temporarily disable any other than hand input */
temparel = startinfv -> arel[1];
startinfv -> arel[1] = NULL;
while (cubarithm_readcube(hdr -> inset, &(hdr -> oric), errormes)) {
/* There was an error */
fprintf(stderr, "INSET %s\n", errormes);
/* Free the name */
free(hdr -> inset);
hdr -> inset = NULL;
/* Doe this */
cancel_tir(startinfv -> arel, "INSET", 0);
/* Read another name from prompt or stop */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "INSET", "Give input cube name (no default).", 0, NULL, 1, 1, 1, 0, &keypres, &nread, &nreturned, &stringlist)) {
startinfv -> arel[1] = temparel;
goto error;
}
/* Put in the name */
if (!(hdr -> inset = simparse_copystring(stringlist[0])))
goto error;
freeparsed(stringlist);
stringlist = NULL;
}
/* Reverse trick */
startinfv -> arel[1] = temparel;
/* Getting a copy is easy */
if (!(hdr -> modelc = cubarithm_copycube(hdr -> oric)))
goto error;
/* padding (don't forget!) */
padcubex(hdr -> oric);
padcubex(hdr -> modelc);
/* Linking, too (is absolutely dangerous and should be removed) */
/* hdr -> ori = hdr -> oric -> points; */
/* hdr -> model = hdr -> modelc ->points; */
/* Input set and subsets and box are in any case necessary, even with a present logfile */
/* err = 0; */
/* sprintf(mes, "Give input set and subsets."); */
/* def = 0; */
/* dev = 0; */
/* class = 1; */
/* classdim = 2; */
/* Get information about input dataset */
hdr -> nsubs = hdr -> oric -> size_v;
/* hdr -> nsubs = gdsinp_tir(hdr -> inset, hdr -> insubs, &maxnsubs, &def, "INSET=", mes, &dev, hdr -> inaxperm, inaxcount, &maxnax, &class, &classdim); */
/* termsinglestr(hdr -> inset); */
/* A box has to be defined inside the specified set, on default whole dataset , not exactly understood */
/* sprintf((mes), "Give area of operation."); */
/* def = 1; */
/* dev = 1; */
/* option = 1; */
/* gdsbox_tir(blo, bhi, hdr -> inset, hdr -> insubs, &maxnsubs, &def, "BOX=", mes, &dev, &option); */
/* def = 0; */
/* The degree of error is not warning (1) but fatal (4) */
/* outerr = 4; */
/* Check the dataset */
/* for (i = 0; i < 3; ++i) { */
/* This is a simple check if CTYPEi is present in the header */
/* err = 0; */
/* sprintf(ciax, "CTYPE%i", hdr -> inaxperm[i]); */
/* /\* For level refer to the description *\/ */
/* level = 0; */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* gdsd_rchar_tir(hdr -> inset, ciax, &level, value, &err); */
/* if (err < 0) { */
/* sprintf(mes, "Header: CTYPE%i not found.", i); */
/* error_tir(&outerr, mes); */
/* } */
/* This is a simple check if CUNITi is present in the header */
/* err = 0; */
/* sprintf(ciax, "CUNIT%i", hdr -> inaxperm[i]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* gdsd_rchar_tir(hdr -> inset, ciax, &(level), value, &err); */
/* if (err < 0) { */
/* sprintf(mes, "Header: CUNIT%i not found.", i); */
/* error_tir(&outerr, mes); */
/* } */
/* This is a check whether the cunit can be converted to modelspacunit, modelmapunit, respectively. At the same time deltsettouser and globsettouser is filled with that conversion factor */
/* if (i < 2) { */
/* err = factor_tir(value, userdeltunit, deltsettouser+i); */
/* if (err) { */
/* dev = 0; */
/* sprintf(mes, "Header: Invalid CUNIT%i", i); */
/* error_tir(&outerr, mes); */
/* } */
/* factor_tir(value, userglobunit, hdr -> globsettouser+i); */
/* } */
/* else { */
/* err = factor_tir(value, user3deltunit, deltsettouser+i); */
/* if (err) { */
/* sprintf(mes, "Header: Invalid CUNIT%i", i); */
/* error_tir(&outerr, mes); */
/* } */
/* factor_tir(value, user3globunit, hdr -> globsettouser+i); */
/* err = 0; */
/* } */
hdr -> globsettouser[0] = 1.;
hdr -> globsettouser[1] = 1.;
hdr -> globsettouser[2] = 0.001;
/* Now check the cdelt */
/* sprintf(ciax, "CDELT%i", hdr -> inaxperm[i]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* level = 0; */
/* gdsd_rdble_tir(hdr -> inset, ciax, &level, setcdelt+i, &err); */
/* if (err < 0) { */
/* sprintf(mes, "Header: CDELT%i not found.", i); */
/* error_tir(&outerr, mes); */
/* } */
/* err = 0; */
/* Now the crpix */
/* sprintf(ciax, "CRPIX%i", hdr -> inaxperm[i]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* For level refer to the description */
/* level = 0; */
/* gdsd_rdble_tir(hdr -> inset, ciax, &level, hdr -> setcrpix+i, &err); */
/* if (err < 0) { */
/* sprintf(mes, "Header: CRPIX%i not found.", i); */
/* error_tir(&dev, mes); */
/* } */
hdr -> setcrpix[0] = hdr -> oric -> refpix_x;
hdr -> setcrpix[1] = hdr -> oric -> refpix_y;
hdr -> setcrpix[2] = hdr -> oric -> refpix_v;
/* Now the crval */
/* sprintf(ciax, "CRVAL%i", hdr -> inaxperm[i]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* For level refer to the description */
/* level = 0; */
/* gdsd_rdble_tir(hdr -> inset, ciax, &level, setcrval+i, &err); */
/* if (err < 0) { */
/* sprintf(mes, "Header: CRVAL%i not found.", i); */
/* error_tir(&dev, mes); */
/* } */
/* hdr -> setcrval[0] = hdr -> oric -> refval_x; */
/* hdr -> setcrval[1] = hdr -> oric -> refval_y; */
/* hdr -> setcrval[2] = hdr -> oric -> refval_v; */
/* The cdelt of the axis in user units, the size of a grid in user units */
/* userdeltcdelt[i] = setcdelt[i]*deltsettouser[i]; */
hdr -> userglobcdelt[0] = hdr -> oric -> delt_x*hdr -> globsettouser[0];
hdr -> userglobcdelt[1] = hdr -> oric -> delt_y*hdr -> globsettouser[1];
hdr -> userglobcdelt[2] = hdr -> oric -> delt_v*hdr -> globsettouser[2];
/* The conversion factors for the user */
hdr -> deltgridtouser[0] = fabs(hdr -> oric -> delt_x*DEGTOARCSEC);
hdr -> deltgridtouser[1] = fabs(hdr -> oric -> delt_y*DEGTOARCSEC);
hdr -> deltgridtouser[2] = fabs(hdr -> oric -> delt_v*hdr -> globsettouser[2]);
hdr -> globgridtouser[0] = fabs(hdr -> oric -> delt_x);
hdr -> globgridtouser[1] = fabs(hdr -> oric -> delt_y);
hdr -> globgridtouser[2] = fabs(hdr -> oric -> delt_v*hdr -> globsettouser[2]);
/* hdr -> globgridtouser[i] = fabs(hdr -> userglobcdelt[i]); */
/* The reference values of the axis in user units */
hdr -> userglobcrval[0] = hdr -> oric -> refval_x*1.;
hdr -> userglobcrval[1] = hdr -> oric -> refval_y*1.;
hdr -> userglobcrval[2] = hdr -> oric -> refval_v*hdr -> globsettouser[2];
hdr -> signv = -hdr -> oric -> delt_v/fabs(hdr -> oric -> delt_v);
/* Calculate the size of the cube in grids along axis 1 and 2 */
/* hdr -> bsize1=bhi[0]-blo[0]+1; */
/* hdr -> bsize2=bhi[1]-blo[1]+1; */
hdr -> bsize1 = hdr -> oric -> size_x;
hdr -> bsize2 = hdr -> oric -> size_y;
/* This is to make a bit more space, take care for allocation */
hdr -> bcsize1= 2*(hdr -> bsize1/2+1);
/* The size of the cube in grids along axis 3 is given by hdr -> nsubs, get the values of the max and min grid */
/* i = 0; */
/* blo[2] = gdsc_grid_tir(hdr -> inset, hdr -> inaxperm+2, hdr -> insubs+i, &err); */
/* i = hdr -> nsubs-1; */
/* bhi[2] = gdsc_grid_tir(hdr -> inset, hdr -> inaxperm+2, hdr -> insubs+i, &err); */
/* Get beam properties */
/* BUGFIX: removed the possibility to read beam properties from header */
/* First check whether this goes automatic */
err = 0;
/* If the cdelt is the same for both spatial axes, go on */
if (fabs(hdr -> userglobcdelt[0]) != fabs(hdr -> userglobcdelt[1])) {
anyout_tir(&outerr, "cdelt of axis1 and axis2 are different");
err = 1;
}
/* err = 0; */
/* check if major axis can be read from the dataset */
/* gdsd_rdble_tir(hdr -> inset, "BMAJ", &level, &vardouble, &err); */
/* if (err < 0) */
/* This is a signal have it manually */
/* manual = 1; */
/* else { */
/* outerr = 0; */
/* This is done under the assumption that the beam is given in set units, i.e. degrees */
hdr -> bmaj = (float) hdr -> oric -> bmaj/fabs(hdr -> oric -> delt_y);
/* sprintf(mes, "Beam major axis in arcsec: %f", hdr -> bmaj*fabs(setcdelt[0])); */
/* anyout_tir(&outerr, mes); */
/* } */
/* err = 0; */
/* check if minor axis can be read from the dataset */
/* gdsd_rdble_tir(hdr -> inset, "BMIN", &level, &vardouble, &err); */
/* if (err < 0) */
/* This is a signal have it manually */
/* manual = 1; */
/* else { */
/* outerr = 0; */
/* This is done under the assumption that the beam is given in set units */
/* hdr -> bmin = (float) vardouble/fabs(setcdelt[1]); */
hdr -> bmin = (float) hdr -> oric -> bmin/fabs(hdr -> oric -> delt_y);
/* sprintf(mes, "Beam minor axis in arcsec: %f", hdr -> bmin*fabs(setcdelt[1])); */
/* anyout_tir(&outerr, mes); */
/* } */
/* err = 0; */
/* check for the bpa */
/* gdsd_rdble_tir(hdr -> inset, "BPA", &level, &vardouble, &err); */
/* if (err < 0) */
/* This is a signal have it manually */
/* manual = 1; */
/* else { */
/* outerr = 0; */
/* CAUTION !!!!! This is done under the assumption that the bpa is always in deg */
hdr -> bpa = (float) hdr -> oric -> bpa;
/* sprintf(mes, "Beam position angle in degrees: %f", hdr -> bpa); */
/* anyout_tir(&outerr, mes); */
/* } */
/* } */
/* If the cdelts are different we pose a warning and enforce manual reading */
/* else { */
/* outerr = 0; */
/* anyout_tir(&outerr, "cdelt of axis1 and axis2 are different"); */
/* } */
/* Read beam properties manually */
/* BUGFIX: removed the possibility to read beam properties from header. This caused too much confusion */
/* manual = 1; */
/* The beam major and minor axis has to be read in manually */
if ((hdr -> bmaj <= 0) || (err) ) {
/* If a proper logfile is present, we set a default and the beam properties are hidden */
def = 4;
sprintf(mes, "Give HPBW of the gaussian beam, major axis, in arcsec.");
nel = 1;
userreal_tir(startinfv -> arel, &hdr -> bmaj, &nel, &def, "BMAJ=", mes);
sprintf(mes, "Give HPBW of the gaussian beam, minor axis, in arcsec.");
nel = 1;
userreal_tir(startinfv -> arel, &hdr -> bmin, &nel, &def, "BMIN=", mes);
sprintf(mes, "Give BPA of the gaussian beam in degrees.");
nel = 1;
userreal_tir(startinfv -> arel, &hdr -> bpa, &nel, &def, "BPA=", mes);
/* Convert from arcsec to grids */
hdr -> bmaj = hdr -> bmaj/hdr -> deltgridtouser[0];
hdr -> bmin = hdr -> bmin/hdr -> deltgridtouser[0];
}
/* Check for the correct intensity units */
err = 0;
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* gdsd_rchar_tir(hdr -> inset, "BUNIT", hdr -> insubs, value, &err); */
/* if ((err == 0) || (err == hdr -> insubs[0])) { */
if (!strcmp(hdr -> oric -> unit, "JY/BEAM") || !strcmp(hdr -> oric -> unit, "jy/beam")) {
sprintf(mes,"Units in the maps should be JY/BEAM, found: |%s|", hdr -> oric -> unit);
/* dev = 0; */
anyout_tir(&dev, mes);
/* outerr = 1; */
anyout_tir(&outerr, "Check if that is ok.");
}
/* } */
/* else { */
/* outerr = 1; */
/* error_tir(&outerr, "No units in the maps found."); */
/* } */
/* Allocate memory for cwlo and -hi */
/* if (!(hdr -> cwhi = (int *) malloc(hdr -> nsubs*sizeof(int)))) */
/* goto error; */
/* if (!(hdr -> cwlo = (int *) malloc(hdr -> nsubs*sizeof(int)))) */
/* goto error; */
/* check the subset grid and set it: The grid value is the relative position with respect to the reference pixel as integer */
/* for (i = 0; i < 0+hdr -> nsubs; ++i) { */
/* hdr -> cwlo[i] = gdsc_fill_tir(hdr -> inset,hdr -> insubs+i, blo); */
/* hdr -> cwhi[i] = gdsc_fill_tir(hdr -> inset,hdr -> insubs+i, bhi); */
/* } */
/* Input of rms */
err = 0;
/* level = 0 ; */
/* gdsd_rreal_tir(hdr -> inset, "RMS", &level, &hdr -> rms, &err); */
/* if (err < 0) { */
def = 4;
sprintf(mes, "Give sigma_rms for input map in map units. [Jy/beam]");
nel = 1;
userreal_tir(startinfv -> arel, &hdr -> rms, &nel, &def, "RMS=", mes);
while (hdr -> rms <= 0) {
sprintf(mes, "Sigma must be positive");
anyout_tir(&nel, mes);
cancel_tir(startinfv -> arel, "RMS", 2);
sprintf(mes, "Give sigma_rms for input map in map units. [Jy/beam]");
nel = 1;
userreal_tir(startinfv -> arel, &hdr -> rms, &nel, &def, "RMS=", mes);
}
/* } */
/* Determine conversion factor for HI column density => intensity */
hdr -> itou = HICONVERSION;
sprintf(mes, "Give intensity to surface density conversion");
def = 2;
nel = 1;
err = 0;
while (!(err)) {
userdble_tir(startinfv -> arel, &hdr -> itou, &nel, &def, "ITOU=", mes);
if (hdr -> itou <= 0.0) {
sprintf(mes, "Must be positive! %f",hdr -> itou);
cancel_tir(startinfv -> arel, "ITOU=", 2);
def = 1;
}
else
err = 1;
}
/* Get rest frequency */
hdr -> rfreq = HIRESFREQ;
sprintf(mes, "Give rest frequency");
def = 2;
nel = 1;
err = 0;
while (!(err)) {
userdble_tir(startinfv -> arel, &hdr -> rfreq, &nel, &def, "RFREQ=", mes);
if (hdr -> rfreq <= 0.0) {
sprintf(mes, "Must be positive!");
cancel_tir(startinfv -> arel, "RFREQ=", 2);
def = 1;
}
else
err = 1;
}
/*******************/
/*******************/
/* Don't try to do this again! */
/* hdr -> cd2i = 1.5147016e-21 + fabs(hdr -> cdelt3)*pow(hdr -> cdelt3*hdr -> midgrid/hdr -> freq0+2.9979246e5/hdr -> drval3, 2); */
/* Determine conversion factor for Jy/arcsec^2 to Jy/pixel, deltgridtouser is in arcsec */
hdr -> jygridtouser = hdr -> deltgridtouser[2]/fabs(hdr -> deltgridtouser[0]*hdr -> deltgridtouser[1]);
/* This could in principle be done elsewhere..., but we can also place it here */
hdr -> nprof = hdr -> bsize1*hdr -> bsize2;
/* Reserve memory */
/* if (!(hdr -> ori = (float *) malloc_engalmod(hdr -> bcsize1*hdr -> bsize2*hdr -> nsubs*sizeof(float)))) { */
/* dev = 0; */
/* anyout_tir(&dev, "Not enough memory to hold a single cube"); */
/* goto error; */
/* } */
/* if (!(hdr -> model = (float *) malloc_engalmod(hdr -> bcsize1*hdr -> bsize2*hdr -> nsubs*sizeof(float)))) { */
/* anyout_tir(&dev, "Not enough memory to hold two cubes"); */
/* goto error; */
/* } */
/* Default is nothing */
/* for (i = 0; i < 200; ++i) */
/* hdr -> outset[i] = ' '; */
/* hdr -> outset[200] = '\0'; */
/* def = 5; */
/* class = 1; */
/* i = 0; */
/* sprintf(mes, "Give output set"); */
/* while(!(i)) { */
/* userchar_tir(hdr -> outset, &class, &def, "OUTSET=", mes); */
/* if (!strcmp(hdr -> inset, hdr -> outset)) { */
/* dev = 0; */
/* sprintf(mes, "Must differ from inset name %s", hdr -> inset); */
/* anyout_tir(&dev, mes); */
/* cancel_tir(startinfv -> arel, "OUTSET="); */
/* def = 5; */
/* } */
/* else */
/* ++i; */
/* } */
/* termsinglestr(hdr -> outset); */
/* If there is an outset, we will open it, else we terminate it */
/* if ((hdr -> outset[0])) { */
/* i = 1; */
/* Copy the information of inset to outset prior to reading it */
/* gdsasn_tir("INSET=", "OUTSET", &i); */
/* gdscss_tir("OUTSET", blo, bhi); */
/* def = 102; */
/* class = 0; */
/* gdsout_tir(hdr -> outset, outsubs, &hdr -> nsubs, &def, "OUTSET", "mes", &class , outaxperm, outaxcount, &maxnax); */
/* We want to get the number to refresh the output cube */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "OUTSET", "Give output cube name.", 0, NULL, 0, 1, 0, 0, &keypres, &nread, &nreturned, &stringlist))
goto error;
if ((stringlist[0])) {
if (!(hdr -> outset = simparse_copystring(stringlist[0])))
goto error;
}
else {
if (!(hdr -> outset = simparse_copystring("")))
goto error;
}
freeparsed(stringlist);
/* Default */
hdr -> outcubup = 1000000;
def = 2;
nel = 1;
class = 0;
while (!(class)) {
userint_tir(startinfv -> arel, &(hdr -> outcubup), &nel, &def, "OUTCUBUP=", mes);
if (hdr -> outcubup < 1) {
sprintf(mes, "Outcubup is least 1!");
cancel_tir(startinfv -> arel, "OUTCUBUP=", 2);
def = 1;
class = 0;
}
else {
++class;
}
}
/* Finished */
return hdr;
error:
if (hdr)
destroy_hdrinf(hdr);
if (log)
/* Number of disks is irrelevant at this point */
destroy_loginf(log, 1);
if (stringlist)
freeparsed(stringlist);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a ringparms structure */
static ringparms *create_ringparms(int ndisks)
{
ringparms *create_ringparms;
int i;
if (!(create_ringparms = (ringparms *) malloc(sizeof(ringparms))))
goto error;
/* Put numbers in the size descriptors */
/* put number to ndisks member */
create_ringparms -> ndisks = ndisks;
/* Initialise all the pointers */
create_ringparms -> par = NULL;
create_ringparms -> oldpar = NULL;
create_ringparms -> chapar = NULL;
create_ringparms -> modpar = NULL;
create_ringparms -> gsl_interparray = NULL;
create_ringparms -> gsl_interp_accelarray = NULL;
create_ringparms -> smothcar = NULL;
create_ringparms -> gsl_indinterparray = NULL;
create_ringparms -> gsl_indinterp_accelarray = NULL;
create_ringparms -> smothindcar = NULL;
create_ringparms -> actarray = NULL;
create_ringparms -> actindar = NULL;
create_ringparms -> interar = NULL;
create_ringparms -> radar = NULL;
create_ringparms -> ltype = NULL;
create_ringparms -> cflux = NULL;
create_ringparms -> allnpoints = NULL;
create_ringparms -> fluxpoints = NULL;
create_ringparms -> sd = NULL;
create_ringparms -> inf_sdisv = NULL;
create_ringparms -> inf_vradv = NULL;
create_ringparms -> inf_vverv = NULL;
create_ringparms -> inf_dvrov = NULL;
create_ringparms -> inf_dvrav = NULL;
create_ringparms -> inf_dvvev = NULL;
create_ringparms -> inf_vm0v = NULL;
create_ringparms -> inf_vm1v = NULL;
create_ringparms -> inf_vm2v = NULL;
create_ringparms -> inf_vm3v = NULL;
create_ringparms -> inf_vm4v = NULL;
create_ringparms -> inf_ra1v = NULL;
create_ringparms -> inf_ra2v = NULL;
create_ringparms -> inf_ra3v = NULL;
create_ringparms -> inf_ra4v = NULL;
create_ringparms -> inf_ro1v = NULL;
create_ringparms -> inf_ro2v = NULL;
create_ringparms -> inf_ro3v = NULL;
create_ringparms -> inf_ro4v = NULL;
create_ringparms -> inf_wm0v = NULL;
create_ringparms -> inf_wm1v = NULL;
create_ringparms -> inf_wm2v = NULL;
create_ringparms -> inf_wm3v = NULL;
create_ringparms -> inf_wm4v = NULL;
create_ringparms -> inf_ls0v = NULL;
create_ringparms -> inf_lc0v = NULL;
create_ringparms -> inf_smiv = NULL;
create_ringparms -> inf_gauv = NULL;
create_ringparms -> inf_aziv = NULL;
if (!(create_ringparms -> sd = (srd **) malloc(create_ringparms -> ndisks*sizeof(srd *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> sd[i] = NULL;}
if (!(create_ringparms -> inf_sdisv = (inf_sdis **) malloc(create_ringparms -> ndisks*sizeof(inf_sdis *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_sdisv[i] = NULL;}
if (!(create_ringparms -> inf_vradv = (inf_vrad **) malloc(create_ringparms -> ndisks*sizeof(inf_vrad *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_vradv[i] = NULL;}
if (!(create_ringparms -> inf_vverv = (inf_vver **) malloc(create_ringparms -> ndisks*sizeof(inf_vver *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_vverv[i] = NULL;}
if (!(create_ringparms -> inf_dvrov = (inf_dvro **) malloc(create_ringparms -> ndisks*sizeof(inf_dvro *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_dvrov[i] = NULL;}
if (!(create_ringparms -> inf_dvrav = (inf_dvra **) malloc(create_ringparms -> ndisks*sizeof(inf_dvra *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_dvrav[i] = NULL;}
if (!(create_ringparms -> inf_dvvev = (inf_dvve **) malloc(create_ringparms -> ndisks*sizeof(inf_dvve *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_dvvev[i] = NULL;}
if (!(create_ringparms -> inf_vm0v = (inf_vm0 **) malloc(create_ringparms -> ndisks*sizeof(inf_vm0 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_vm0v[i] = NULL;}
if (!(create_ringparms -> inf_vm1v = (inf_vm1 **) malloc(create_ringparms -> ndisks*sizeof(inf_vm1 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_vm1v[i] = NULL;}
if (!(create_ringparms -> inf_vm2v = (inf_vm2 **) malloc(create_ringparms -> ndisks*sizeof(inf_vm2 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_vm2v[i] = NULL;}
if (!(create_ringparms -> inf_vm3v = (inf_vm3 **) malloc(create_ringparms -> ndisks*sizeof(inf_vm3 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_vm3v[i] = NULL;}
if (!(create_ringparms -> inf_vm4v = (inf_vm4 **) malloc(create_ringparms -> ndisks*sizeof(inf_vm4 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_vm4v[i] = NULL;}
if (!(create_ringparms -> inf_ra1v = (inf_ra1 **) malloc(create_ringparms -> ndisks*sizeof(inf_ra1 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ra1v[i] = NULL;}
if (!(create_ringparms -> inf_ra2v = (inf_ra2 **) malloc(create_ringparms -> ndisks*sizeof(inf_ra2 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ra2v[i] = NULL;}
if (!(create_ringparms -> inf_ra3v = (inf_ra3 **) malloc(create_ringparms -> ndisks*sizeof(inf_ra3 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ra3v[i] = NULL;}
if (!(create_ringparms -> inf_ra4v = (inf_ra4 **) malloc(create_ringparms -> ndisks*sizeof(inf_ra4 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ra4v[i] = NULL;}
if (!(create_ringparms -> inf_ro1v = (inf_ro1 **) malloc(create_ringparms -> ndisks*sizeof(inf_ro1 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ro1v[i] = NULL;}
if (!(create_ringparms -> inf_ro2v = (inf_ro2 **) malloc(create_ringparms -> ndisks*sizeof(inf_ro2 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ro2v[i] = NULL;}
if (!(create_ringparms -> inf_ro3v = (inf_ro3 **) malloc(create_ringparms -> ndisks*sizeof(inf_ro3 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ro3v[i] = NULL;}
if (!(create_ringparms -> inf_ro4v = (inf_ro4 **) malloc(create_ringparms -> ndisks*sizeof(inf_ro4 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ro4v[i] = NULL;}
if (!(create_ringparms -> inf_wm0v = (inf_wm0 **) malloc(create_ringparms -> ndisks*sizeof(inf_wm0 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_wm0v[i] = NULL;}
if (!(create_ringparms -> inf_wm1v = (inf_wm1 **) malloc(create_ringparms -> ndisks*sizeof(inf_wm1 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_wm1v[i] = NULL;}
if (!(create_ringparms -> inf_wm2v = (inf_wm2 **) malloc(create_ringparms -> ndisks*sizeof(inf_wm2 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_wm2v[i] = NULL;}
if (!(create_ringparms -> inf_wm3v = (inf_wm3 **) malloc(create_ringparms -> ndisks*sizeof(inf_wm3 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_wm3v[i] = NULL;}
if (!(create_ringparms -> inf_wm4v = (inf_wm4 **) malloc(create_ringparms -> ndisks*sizeof(inf_wm4 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_wm4v[i] = NULL;}
if (!(create_ringparms -> inf_ls0v = (inf_ls0 **) malloc(create_ringparms -> ndisks*sizeof(inf_ls0 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_ls0v[i] = NULL;}
if (!(create_ringparms -> inf_lc0v = (inf_lc0 **) malloc(create_ringparms -> ndisks*sizeof(inf_lc0 *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_lc0v[i] = NULL;}
if (!(create_ringparms -> inf_smiv = (inf_smi **) malloc(create_ringparms -> ndisks*sizeof(inf_smi *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_smiv[i] = NULL;}
if (!(create_ringparms -> inf_gauv = (inf_gau **) malloc(create_ringparms -> ndisks*sizeof(inf_gau *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_gauv[i] = NULL;}
if (!(create_ringparms -> inf_aziv = (inf_azi **) malloc(create_ringparms -> ndisks*sizeof(inf_azi *)))) goto error; for (i = 0; i < create_ringparms -> ndisks; ++i) {create_ringparms -> inf_aziv[i] = NULL;}
/* Now allocate more memory */
if (!(create_ringparms -> ltype = (int *) malloc(create_ringparms -> ndisks*sizeof(int))))
goto error;
if (!(create_ringparms -> cflux = (double *) malloc(create_ringparms -> ndisks*sizeof(double))))
goto error;
if (!(create_ringparms -> allnpoints = (int *) malloc(create_ringparms -> ndisks*sizeof(int))))
goto error;
if (!(create_ringparms -> fluxpoints = (long *) malloc(create_ringparms -> ndisks*sizeof(long))))
goto error;
return create_ringparms;
error:
destroy_ringparms(create_ringparms);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Destroys a ringparms structure */
void destroy_ringparms(ringparms *prm)
{
int i;
/* Check if it is there */
if (!(prm))
return;
if ((prm -> par))
free(prm -> par);
if ((prm -> oldpar))
free(prm -> oldpar);
if ((prm -> chapar))
free(prm -> chapar);
if ((prm -> gsl_interparray)) {
for (i = 0; i < prm -> ndisks*NDPARAMS; ++i) {
if ((prm -> gsl_interparray[i]))
gsl_interp_free(prm -> gsl_interparray[i]);
}
free(prm -> gsl_interparray);
}
if ((prm -> gsl_interp_accelarray)) {
for (i = 0; i < prm -> ndisks*NDPARAMS; ++i) {
if ((prm -> gsl_interp_accelarray[i]))
gsl_interp_accel_free(prm -> gsl_interp_accelarray[i]);
}
free(prm -> gsl_interp_accelarray);
}
if ((prm -> smothcar))
free(prm -> smothcar);
if ((prm -> gsl_indinterparray)) {
for (i = 0; i < prm -> ndisks*NDPARAMS; ++i) {
if ((prm -> gsl_indinterparray[i]))
gsl_interp_free(prm -> gsl_indinterparray[i]);
}
free(prm -> gsl_indinterparray);
}
if ((prm -> gsl_indinterp_accelarray)) {
for (i = 0; i < prm -> ndisks*NDPARAMS; ++i) {
if ((prm -> gsl_indinterp_accelarray[i]))
gsl_interp_accel_free(prm -> gsl_indinterp_accelarray[i]);
}
free(prm -> gsl_indinterp_accelarray);
}
if ((prm -> smothindcar))
free(prm -> smothindcar);
if ((prm -> actarray))
free(prm -> actarray);
if ((prm -> actindar))
free(prm -> actindar);
if ((prm -> interar ))
free(prm -> interar );
if ((prm -> radar ))
free(prm -> radar );
if (prm -> ltype)
free(prm -> ltype);
if (prm -> cflux)
free(prm -> cflux);
/* GJnew */
if (prm -> allnpoints)
free(prm -> allnpoints);
if (prm -> fluxpoints)
free(prm -> fluxpoints);
if (prm -> sd != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> sd[i] != NULL) destroy_srd(prm -> sd[i], prm -> nr);} free(prm -> sd);}
if (prm -> inf_sdisv != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_sdisv[i] != NULL) destroy_inf_sdis(prm -> inf_sdisv[i]);} free(prm -> inf_sdisv);}
if (prm -> inf_vradv != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_vradv[i] != NULL) destroy_inf_vrad(prm -> inf_vradv[i]);} free(prm -> inf_vradv);}
if (prm -> inf_vverv != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_vverv[i] != NULL) destroy_inf_vver(prm -> inf_vverv[i]);} free(prm -> inf_vverv);}
if (prm -> inf_dvrov != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_dvrov[i] != NULL) destroy_inf_dvro(prm -> inf_dvrov[i]);} free(prm -> inf_dvrov);}
if (prm -> inf_dvrav != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_dvrav[i] != NULL) destroy_inf_dvra(prm -> inf_dvrav[i]);} free(prm -> inf_dvrav);}
if (prm -> inf_dvvev != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_dvvev[i] != NULL) destroy_inf_dvve(prm -> inf_dvvev[i]);} free(prm -> inf_dvvev);}
if (prm -> inf_vm0v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_vm0v[i] != NULL) destroy_inf_vm0(prm -> inf_vm0v[i]);} free(prm -> inf_vm0v);}
if (prm -> inf_vm1v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_vm1v[i] != NULL) destroy_inf_vm1(prm -> inf_vm1v[i]);} free(prm -> inf_vm1v);}
if (prm -> inf_vm2v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_vm2v[i] != NULL) destroy_inf_vm2(prm -> inf_vm2v[i]);} free(prm -> inf_vm2v);}
if (prm -> inf_vm3v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_vm3v[i] != NULL) destroy_inf_vm3(prm -> inf_vm3v[i]);} free(prm -> inf_vm3v);}
if (prm -> inf_vm4v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_vm4v[i] != NULL) destroy_inf_vm4(prm -> inf_vm4v[i]);} free(prm -> inf_vm4v);}
if (prm -> inf_ra1v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ra1v[i] != NULL) destroy_inf_ra1(prm -> inf_ra1v[i]);} free(prm -> inf_ra1v);}
if (prm -> inf_ra2v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ra2v[i] != NULL) destroy_inf_ra2(prm -> inf_ra2v[i]);} free(prm -> inf_ra2v);}
if (prm -> inf_ra3v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ra3v[i] != NULL) destroy_inf_ra3(prm -> inf_ra3v[i]);} free(prm -> inf_ra3v);}
if (prm -> inf_ra4v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ra4v[i] != NULL) destroy_inf_ra4(prm -> inf_ra4v[i]);} free(prm -> inf_ra4v);}
if (prm -> inf_ro1v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ro1v[i] != NULL) destroy_inf_ro1(prm -> inf_ro1v[i]);} free(prm -> inf_ro1v);}
if (prm -> inf_ro2v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ro2v[i] != NULL) destroy_inf_ro2(prm -> inf_ro2v[i]);} free(prm -> inf_ro2v);}
if (prm -> inf_ro3v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ro3v[i] != NULL) destroy_inf_ro3(prm -> inf_ro3v[i]);} free(prm -> inf_ro3v);}
if (prm -> inf_ro4v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ro4v[i] != NULL) destroy_inf_ro4(prm -> inf_ro4v[i]);} free(prm -> inf_ro4v);}
if (prm -> inf_wm0v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_wm0v[i] != NULL) destroy_inf_wm0(prm -> inf_wm0v[i]);} free(prm -> inf_wm0v);}
if (prm -> inf_wm1v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_wm1v[i] != NULL) destroy_inf_wm1(prm -> inf_wm1v[i]);} free(prm -> inf_wm1v);}
if (prm -> inf_wm2v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_wm2v[i] != NULL) destroy_inf_wm2(prm -> inf_wm2v[i]);} free(prm -> inf_wm2v);}
if (prm -> inf_wm3v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_wm3v[i] != NULL) destroy_inf_wm3(prm -> inf_wm3v[i]);} free(prm -> inf_wm3v);}
if (prm -> inf_wm4v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_wm4v[i] != NULL) destroy_inf_wm4(prm -> inf_wm4v[i]);} free(prm -> inf_wm4v);}
if (prm -> inf_ls0v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_ls0v[i] != NULL) destroy_inf_ls0(prm -> inf_ls0v[i]);} free(prm -> inf_ls0v);}
if (prm -> inf_lc0v != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_lc0v[i] != NULL) destroy_inf_lc0(prm -> inf_lc0v[i]);} free(prm -> inf_lc0v);}
if (prm -> inf_smiv != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_smiv[i] != NULL) destroy_inf_smi(prm -> inf_smiv[i]);} free(prm -> inf_smiv);}
if (prm -> inf_gauv != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_gauv[i] != NULL) destroy_inf_gau(prm -> inf_gauv[i]);} free(prm -> inf_gauv);}
if (prm -> inf_aziv != NULL) {for (i = 0; i < prm -> ndisks; ++i) {if (prm -> inf_aziv[i] != NULL) destroy_inf_azi(prm -> inf_aziv[i]);} free(prm -> inf_aziv);}
for (i = 0; i < prm -> ndisks; ++i) {
/* if((prm -> permrandstr[i])) */
/* free(prm -> permrandstr[i]); */
/* if((prm -> inf_sdisv[i])) */
/* destroy_inf_sdis(prm -> inf_sdisv[i]); */
/* if((prm -> inf_vradv[i])) */
/* destroy_inf_vrad(prm -> inf_vradv[i]); */
/* if((prm -> inf_vverv[i])) */
/* destroy_inf_vver(prm -> inf_vverv[i]); */
/* if((prm -> inf_dvrov[i])) */
/* destroy_inf_dvro(prm -> inf_dvrov[i]); */
/* if((prm -> inf_dvrav[i])) */
/* destroy_inf_dvra(prm -> inf_dvrav[i]); */
/* if((prm -> inf_dvvev[i])) */
/* destroy_inf_dvve(prm -> inf_dvvev[i]); */
/* if((prm -> inf_vm1v[i])) */
/* destroy_inf_vm1(prm -> inf_vm1v[i]); */
/* if((prm -> inf_vm0v[i] )) */
/* destroy_inf_vm0 (prm -> inf_vm0v[i] ); */
/* if((prm -> inf_vm2v[i])) */
/* destroy_inf_vm2(prm -> inf_vm2v[i]); */
/* if((prm -> inf_vm3v[i])) */
/* destroy_inf_vm3(prm -> inf_vm3v[i]); */
/* if((prm -> inf_vm4v[i])) */
/* destroy_inf_vm4(prm -> inf_vm4v[i]); */
/* if((prm -> inf_wm1v[i])) */
/* destroy_inf_wm1(prm -> inf_wm1v[i]); */
/* if((prm -> inf_wm0v[i] )) */
/* destroy_inf_wm0 (prm -> inf_wm0v[i] ); */
/* if((prm -> inf_wm2v[i])) */
/* destroy_inf_wm2(prm -> inf_wm2v[i]); */
/* if((prm -> inf_wm3v[i])) */
/* destroy_inf_wm3(prm -> inf_wm3v[i]); */
/* if((prm -> inf_wm4v[i])) */
/* destroy_inf_wm4(prm -> inf_wm4v[i]); */
/* if((prm -> inf_ls0v[i] )) */
/* destroy_inf_ls0 (prm -> inf_ls0v[i] ); */
/* if((prm -> inf_lc0v[i] )) */
/* destroy_inf_lc0 (prm -> inf_lc0v[i] ); */
/* if((prm -> inf_smiv[i] )) */
/* destroy_inf_smi (prm -> inf_smiv[i] ); */
/* if((prm -> inf_gauv[i] )) */
/* destroy_inf_gau (prm -> inf_gauv[i] ); */
/* if((prm -> inf_aziv[i] )) */
/* destroy_inf_azi (prm -> inf_aziv[i] ); */
}
if (prm -> modpar != NULL)
free(prm -> modpar);
free(prm);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a list of subring descriptors with n elements */
static srd *create_srd(int n)
{
int i;
srd *sd;
if (!(sd = (srd *) malloc(n*sizeof(srd))))
return NULL;
for (i = 0; i < n; ++i) {
(sd+i) -> pl = NULL;
#ifdef PBCORR
(sd+i) -> pbfac = NULL;
#endif
(sd+i) -> permrandstr = NULL;
(sd+i) -> randstr = NULL;
(sd+i) -> grandstr[0] = NULL;
(sd+i) -> grandstr[1] = NULL;
(sd+i) -> grandstr[2] = NULL;
(sd+i) -> grandstr[3] = NULL;
(sd+i) -> srandstr = NULL;
/* There is only one dispersion */
(sd+i) -> nsubcl = 1;
(sd+i) -> nsubclinv = 1.0;
(sd+i) -> y2 = -1024.0;
}
return sd;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a list of subring descriptors with n elements */
static void destroy_srd(srd *sd, int n)
{
int i;
if (!(sd))
return;
for (i = 0; i < n; ++i) {
free(sd[i].pl);
#ifdef PBCORR
if (sd[i].pbfac)
free(sd[i].pbfac);
#endif
if (sd[i].permrandstr)
free(sd[i].permrandstr);
if (sd[i].randstr)
free(sd[i].randstr);
if (sd[i].grandstr[0])
free(sd[i].grandstr[0]);
if (sd[i].grandstr[1])
free(sd[i].grandstr[1]);
if (sd[i].grandstr[2])
free(sd[i].grandstr[2]);
if (sd[i].grandstr[3])
free(sd[i].grandstr[3]);
if (sd[i].srandstr)
free(sd[i].srandstr);
}
free(sd);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Fill the ringparms struct from the input */
static ringparms *get_ringparms(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *ringparmsv)
{
ringparms *rpm;
double globin[3]; /* For the conversion of coordinates in map units */
double globout[3]; /* For the conversion of coordinates in map units */
/* Private control and changing variables */
int def; /* Any default mode */
int nel; /* Number of elements */
int err; /* Error code */
int dummy;
char mes[81]; /* Any message */
char placer[10];
int inty, indinty; /* interpolation type */
const gsl_interp_type * intytype; /* same, only internal to gsl */
const gsl_interp_type * indintytype; /* same, only internal to gsl */
int i,j = 0; /* Simple control variables */
int disk; /* number of the disk */
/* Read values that are needed only in this module */
int mode; /* For memory handling */
int ndisks;
int pcondisp, condisp;
/* primary beam stuff */
#ifdef PBCORR
int pbtel;
double pbrefpix[2];
double pbreffreq;
double pbdoublev1, pbdoublev2, pbradius, pbwsrtconst;
int dev = 1;
#endif
/* Get the number of disks */
/* Default */
if (startinfv -> firstrun) {
def = 2;
ndisks = 0;
nel = 1;
userint_tir(startinfv -> arel, &ndisks, &nel, &def, "NDISKS=", mes);
if (ndisks < 1)
ndisks = NDISKS;
/* Get the struct */
if (!(rpm = create_ringparms(ndisks)))
goto error;
}
else {
rpm = ringparmsv;
}
/* Activate the logfile info, the reason that the function is called here is that the number of disks is required */
/* Now we try to open the table object with the logfile name */
if (activateftstab(startinfv, log, rpm)) {
goto error;
}
if (startinfv -> firstrun) {
/* Get the number of rings */
/* Default */
def = 0;
i = 0;
sprintf(mes, "Give number of rings.");
while (!(i)) {
nel = 1;
userint_tir(startinfv -> arel, &rpm -> nur, &nel, &def, "NUR=", mes);
if (rpm -> nur < 2) {
sprintf(mes, "At least 2!");
cancel_tir(startinfv -> arel, "NUR=", 2);
i = 0;
}
else {
/* Do some allocation that hides some variables in this function */
if (!(rpm -> par = (double *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(double))))
goto error;
/* Do some allocation that hides some variables in this function */
if (!(rpm -> oldpar = (double *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(double))))
goto error;
/* Do some allocation that hides some variables in this function, same size as par and oldpar to ease indexing */
if (!(rpm -> chapar = (int *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(int))))
goto error;
for (j = 0; j < (rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS); ++j)
rpm -> chapar[j] = 0;
/* Allocate the interpolation structures */
if (!(rpm -> gsl_interparray = (gsl_interp **) malloc(rpm -> ndisks*NDPARAMS*sizeof(gsl_interp *))))
goto error;
for (j = 0; j < rpm -> ndisks*NDPARAMS; ++j)
rpm -> gsl_interparray[j] = NULL;
if (!(rpm -> gsl_interp_accelarray = (gsl_interp_accel **) malloc(rpm -> ndisks*NDPARAMS*sizeof(gsl_interp_accel *))))
goto error;
for (j = 0; j < rpm -> ndisks*NDPARAMS; ++j)
rpm -> gsl_interp_accelarray[j] = NULL;
if (!(rpm -> smothcar = (int *) malloc(rpm -> ndisks*NDPARAMS*sizeof(int))))
goto error;
if (!(rpm -> gsl_indinterparray = (gsl_interp **) malloc(rpm -> ndisks*NDPARAMS*sizeof(gsl_interp *))))
goto error;
for (j = 0; j < rpm -> ndisks*NDPARAMS; ++j)
rpm -> gsl_indinterparray[j] = NULL;
if (!(rpm -> gsl_indinterp_accelarray = (gsl_interp_accel **) malloc(rpm -> ndisks*NDPARAMS*sizeof(gsl_interp_accel *))))
goto error;
for (j = 0; j < rpm -> ndisks*NDPARAMS; ++j)
rpm -> gsl_indinterp_accelarray[j] = NULL;
if (!(rpm -> smothindcar = (int *) malloc(rpm -> ndisks*NDPARAMS*sizeof(int))))
goto error;
if (!(rpm -> actarray = (int *) malloc(rpm -> nur * sizeof(int))))
goto error;
if (!(rpm -> actindar = (int *) malloc(rpm -> nur * sizeof(int))))
goto error;
if (!(rpm -> interar = (double *) malloc(rpm -> nur * sizeof(double))))
goto error;
if (!(rpm -> radar = (double *) malloc(rpm -> nur * sizeof(double))))
goto error;
++i;
}
}
/* The output array contains rpm -> maxparnur + 3 fields (3 -> chisquare, accept, number) */
if (!(log -> outarray = (double *) malloc (((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR) * sizeof(double))))
goto error;
if (!(log -> grid = (double *) malloc (((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR) * sizeof(double))))
goto error;
if (!(log -> radius = (double *) malloc (((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR) * sizeof(double))))
goto error;
if (!(log -> regist = (double *) malloc (((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR) * sizeof(double))))
goto error;
/* Get the subring width in grid units */
/* Default */
rpm -> radsep = 0.75;
sprintf(mes, "Give subring width (grids)");
def = 2;
nel = 1;
err = 0;
while (!(err)) {
userdble_tir(startinfv -> arel, &rpm -> radsep, &nel, &def, "RADSEP=", mes);
if (rpm -> radsep <= 0.0) {
sprintf(mes, "Must be positive!");
cancel_tir(startinfv -> arel, "RADSEP=", 2);
def = 1;
}
else
err = 1;
}
/* Get the default interpolation method */
/* 0: linear, 1: natural spline, default 0 */
inty = INTERP_LINEAR;
sprintf(mes, "Give default interpolation type");
def = 2;
nel = 1;
err = 0;
while (!(err)) {
userint_tir(startinfv -> arel, &inty, &nel, &def, "INTY=", mes);
if (inty < 0 || inty >= INTERP_NUMBER) {
sprintf(mes, "Must lie between %i and %i!", 0, INTERP_NUMBER-1);
cancel_tir(startinfv -> arel, "INTY=", 2);
def = 1;
}
else
err = 1;
}
/* Now allocate all the interpolation structs and "accelerators" */
switch (inty) {
case INTERP_LINEAR:
intytype = gsl_interp_linear;
break;
case INTERP_CSPLINE:
if (rpm -> nur > 2){
intytype = gsl_interp_cspline;
}
else {
sprintf(mes, "Must have at least 3 radii for spline, using linear");
anyout_tir(&err, mes);
intytype = gsl_interp_linear;
}
break;
case INTERP_AKIMA:
if (rpm -> nur > 4) {
intytype = gsl_interp_akima;
}
else {
sprintf(mes, "Must have at least 5 radii for Akima");
anyout_tir(&err, mes);
if (rpm -> nur > 2) {
sprintf(mes, "Using natural cubic spline");
anyout_tir(&err, mes);
intytype = gsl_interp_cspline;
}
else {
sprintf(mes, "Using linear");
anyout_tir(&err, mes);
intytype = gsl_interp_linear;
}
}
break;
/* No real default */
default:
break;
}
/* Real allocation here */
for (i = 0; i < rpm -> ndisks*NDPARAMS; ++i) {
if (!(rpm -> gsl_interparray[i] = gsl_interp_alloc(intytype, rpm -> nur)))
goto error;
/* printf("%s"); */
if (!(rpm -> gsl_interp_accelarray[i] = gsl_interp_accel_alloc()))
goto error;
rpm -> smothcar[i] = inty;
}
/* Get the default interpolation method */
/* 0: linear, 1: natural spline, default 0 */
indinty = inty;
sprintf(mes, "Give default interpolation type");
def = 2;
nel = 1;
err = 0;
while (!(err)) {
userint_tir(startinfv -> arel, &indinty, &nel, &def, "INDINTY=", mes);
if (indinty < 0 || indinty >= INTERP_NUMBER) {
sprintf(mes, "Must lie between %i and %i!", 0, INTERP_NUMBER-1);
cancel_tir(startinfv -> arel, "INDINTY=", 2);
def = 1;
}
else
err = 1;
}
/* Now allocate all the interpolation structs and "accelerators" */
switch (indinty) {
case INTERP_LINEAR:
indintytype = gsl_interp_linear;
break;
case INTERP_CSPLINE:
if (rpm -> nur > 2)
indintytype = gsl_interp_cspline;
else {
sprintf(mes, "Must have at least 3 radii for spline, using linear");
anyout_tir(&err, mes);
indintytype = gsl_interp_linear;
}
break;
case INTERP_AKIMA:
if (rpm -> nur > 4) {
indintytype = gsl_interp_akima;
}
else {
sprintf(mes, "Must have at least 5 radii for Akima");
anyout_tir(&err, mes);
if (rpm -> nur > 2) {
sprintf(mes, "Using natural cubic spline");
anyout_tir(&err, mes);
indintytype = gsl_interp_cspline;
}
else {
sprintf(mes, "Using linear");
anyout_tir(&err, mes);
indintytype = gsl_interp_linear;
}
}
break;
/* No real default */
default:
break;
}
/* Real allocation here */
for (i = 0; i < rpm -> ndisks*NDPARAMS; ++i) {
if (!(rpm -> gsl_indinterparray[i] = gsl_interp_alloc(indintytype, rpm -> nur)))
goto error;
/* printf("%s"); */
if (!(rpm -> gsl_indinterp_accelarray[i] = gsl_interp_accel_alloc()))
goto error;
rpm -> smothindcar[i] = indinty;
}
/* Now get all sorts of parameters */
/* Radii is the most complicated */
err = 0;
while (!(err)) {
get_parameter_double(startinfv, log, hdr, rpm, "Give Radii. (arcsec)", "RADI=", PRADI, 4);
/* Enforce the first radius to be 0 */
if (rpm -> par[0] != 0.0) {
sprintf(mes, "First radius has to be 0.0");
anyout_tir(&err, mes);
/* The difference to reject is unclear to me */
cancel_tir(startinfv -> arel, "RADI=", 2);
}
else {
/* Now check whether the modpar array can be constructed */
/* Identify the number of subrings, the max radius of a subring is the max radius in parameter struct plus the half of the width of a subring, which is ususally 0.75 pixels */
rpm -> nr = ((int) (rpm -> par[(PRADI+1)*rpm -> nur-1]/rpm -> radsep-0.5))+1;
/* ndisk construction */
/* Allocation of subring array */
if (!(rpm -> modpar = (float *) malloc((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nr*sizeof(float))))
goto error;
err = 1;
for (i = 1; i < rpm -> nur; ++i) {
/* Check if the choice of radii is sensible */
if ((rpm -> par[PRADI*rpm -> nur+i-1]+rpm -> radsep) >= (rpm -> par[PRADI*rpm -> nur+i])) {
sprintf(mes, "Radius separation too small or radii not in increasing order.");
err = 0;
anyout_tir(&err, mes);
cancel_tir(startinfv -> arel, "RADI=", 2);
break;
}
}
}
}
}
/* other parameters */
get_parameter_double(startinfv, log, hdr, rpm, "Give circular velocities. (km/s)", "VROT=", PVROT, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocities. (km/s)", "VRAD=", PVRAD, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give vertical velocities. (km/s)", "VVER=", PVVER, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give vertical gradient of circular velocities. (km/s)", "DVRO=", PDVRO, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give vertical gradient of radial velocities. (km/s)", "DVRA=", PDVRA, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give vertical gradient of vertical velocities. (km/s)", "DVVE=", PDVVE, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give start height for change of circular velocities. (km/s)", "ZDRO=", PZDRO, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give start height for change of radial velocities. (km/s)", "ZDRA=", PZDRA, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give start height for change of vertical velocities. (km/s)", "ZDVE=", PZDVE, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion (SDIS) of rings. (km/s)", "SDIS=", PSDIS, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give number of sub-clouds", "CLNR=", PCLNR, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity term", "VM0A=", PVM0A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m1 term, amp ", "VM1A=", PVM1A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m1 term, phase", "VM1P=", PVM1P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m2 term, amp ", "VM2A=", PVM2A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m2 term, phase", "VM2P=", PVM2P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m3 term, amp ", "VM3A=", PVM3A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m3 term, phase", "VM3P=", PVM3P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m4 term, amp ", "VM4A=", PVM4A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m4 term, phase", "VM4P=", PVM4P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m1 term, phase", "RO1A=", PRO1A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m1 term, phase", "RO1P=", PRO1P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m2 term, amp ", "RO2A=", PRO2A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m2 term, phase", "RO2P=", PRO2P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m3 term, amp ", "RO3A=", PRO3A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m3 term, phase", "RO3P=", PRO3P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m4 term, amp ", "RO4A=", PRO4A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m4 term, phase", "RO4P=", PRO4P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m1 term, phase", "RA1A=", PRA1A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m1 term, phase", "RA1P=", PRA1P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m2 term, amp ", "RA2A=", PRA2A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m2 term, phase", "RA2P=", PRA2P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m3 term, amp ", "RA3A=", PRA3A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m3 term, phase", "RA3P=", PRA3P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m4 term, amp ", "RA4A=", PRA4A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m4 term, phase", "RA4P=", PRA4P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give 0th order warp term", "WM0A=", PWM0A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m1 term, amp ", "WM1A=", PWM1A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m1 term, phase", "WM1P=", PWM1P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m2 term, amp ", "WM2A=", PWM2A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m2 term, phase", "WM2P=", PWM2P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m3 term, amp ", "WM3A=", PWM3A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m3 term, phase", "WM3P=", PWM3P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m4 term, amp ", "WM4A=", PWM4A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give warp m4 term, phase", "WM4P=", PWM4P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give S0 lopsided term", "LS0=", PLS0, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give C0 lopsided term", "LC0=", PLC0, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give scale-height (Z0) of rings. (arcsec)", "Z0=", PZ0, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface-brightness of rings. (Jy/(arcsec*arcsec))", "SBR=", PSBR, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m1 term, amp (Jy/(arcsec*arcsec))", "SM1A=", PSM1A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m1 term, phase (deg)", "SM1P=", PSM1P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m2 term, amp (Jy/(arcsec*arcsec))", "SM2A=", PSM2A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m2 term, phase (deg)", "SM2P=", PSM2P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m3 term, amp (Jy/(arcsec*arcsec))", "SM3A=", PSM3A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m3 term, phase (deg)", "SM3P=", PSM3P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m4 term, amp (Jy/(arcsec*arcsec))", "SM4A=", PSM4A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m4 term, phase (deg)", "SM4P=", PSM4P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 1 (Jy/(arcsec*arcsec))", "GA1A", PGA1A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 1 (deg)", "GA1P", PGA1P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 1 (arcsec)", "GA1D", PGA1D, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 2 (Jy/(arcsec*arcsec))", "GA2A", PGA2A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 2 (deg)", "GA2P", PGA2P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 2 (arcsec)", "GA2D", PGA2D, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 3 (Jy/(arcsec*arcsec))", "GA3A", PGA3A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 3 (deg)", "GA3P", PGA3P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 3 (arcsec)", "GA3D", PGA3D, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 4 (Jy/(arcsec*arcsec))", "GA4A", PGA4A, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 4 (deg)", "GA4P", PGA4P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 4 (arcsec)", "GA4D", PGA4D, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of simulted range 1 (deg)", "AZ1P", PAZ1P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give width of simulted range 1 (deg)", "AZ1W", PAZ1W, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of simulted range 2 (deg)", "AZ2P", PAZ2P, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give width of simulted range 2 (deg)", "AZ2W", PAZ2W, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give inclinations of rings. (degrees)", "INCL=", PINCL, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give position angle of rings. (degrees)", "PA=", PPA, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give Right Ascensions of ring centres. (degrees)", "XPOS=", PXPOS, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give Declinations of ring centres. (degrees)", "YPOS=", PYPOS, 2);
get_parameter_double(startinfv, log, hdr, rpm, "Give systemic velocities of rings in (km/s).", "VSYS=", PVSYS, 2);
/* We do this ndisks time */
for (disk = 1; disk < rpm -> ndisks; ++disk) {
sprintf(placer, "VROT_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give circular velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PVROT, 2);
sprintf(placer, "VRAD_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PVRAD, 2);
sprintf(placer, "VVER_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give vertical velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PVVER, 2);
sprintf(placer, "DVRO_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give vertical gradient of circular velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PDVRO, 2);
sprintf(placer, "DVRA_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give vertical gradient of radial velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PDVRA, 2);
sprintf(placer, "DVVE_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give vertical gradient of vertical velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PDVVE, 2);
sprintf(placer, "ZDRO_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give start height for change of circular velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PZDRO, 2);
sprintf(placer, "ZDRA_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give start height for change of velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PZDRA, 2);
sprintf(placer, "ZDVE_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give start height for change of vertical velocities. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PZDVE, 2);
sprintf(placer, "SDIS_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion (SDIS) of rings. (km/s)", placer, PRPARAMS+disk*NDPARAMS+PSDIS, 2);
sprintf(placer, "CLNR_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give number of sub-clouds", placer, PRPARAMS+disk*NDPARAMS+PCLNR, 2);
sprintf(placer, "VM0A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity term", placer, PRPARAMS+disk*NDPARAMS+PVM0A, 2);
sprintf(placer, "VM1A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m1 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PVM1A, 2);
sprintf(placer, "VM1P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m1 term, phase", placer, PRPARAMS+disk*NDPARAMS+PVM1P, 2);
sprintf(placer, "VM2A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m2 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PVM2A, 2);
sprintf(placer, "VM2P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m2 term, phase", placer, PRPARAMS+disk*NDPARAMS+PVM2P, 2);
sprintf(placer, "VM3A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m3 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PVM3A, 2);
sprintf(placer, "VM3P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m3 term, phase", placer, PRPARAMS+disk*NDPARAMS+PVM3P, 2);
sprintf(placer, "VM4A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m4 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PVM4A, 2);
sprintf(placer, "VM4P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give velocity m4 term, phase", placer, PRPARAMS+disk*NDPARAMS+PVM4P, 2);
sprintf(placer, "RA1A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m1 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRA1A, 2);
sprintf(placer, "RA1P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m1 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRA1P, 2);
sprintf(placer, "RA2A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m2 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRA2A, 2);
sprintf(placer, "RA2P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m2 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRA2P, 2);
sprintf(placer, "RA3A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m3 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRA3A, 2);
sprintf(placer, "RA3P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m3 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRA3P, 2);
sprintf(placer, "RA4A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m4 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRA4A, 2);
sprintf(placer, "RA4P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give radial velocity m4 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRA4P, 2);
sprintf(placer, "RO1A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m1 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRO1A, 2);
sprintf(placer, "RO1P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m1 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRO1P, 2);
sprintf(placer, "RO2A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m2 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRO2A, 2);
sprintf(placer, "RO2P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m2 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRO2P, 2);
sprintf(placer, "RO3A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m3 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRO3A, 2);
sprintf(placer, "RO3P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m3 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRO3P, 2);
sprintf(placer, "RO4A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m4 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PRO4A, 2);
sprintf(placer, "RO4P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give tangential velocity m4 term, phase", placer, PRPARAMS+disk*NDPARAMS+PRO4P, 2);
sprintf(placer, "WM0A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give 0th order warp term", placer, PRPARAMS+disk*NDPARAMS+PWM0A, 2);
sprintf(placer, "WM1A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m1 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PWM1A, 2);
sprintf(placer, "WM1P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m1 term, phase", placer, PRPARAMS+disk*NDPARAMS+PWM1P, 2);
sprintf(placer, "WM2A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m2 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PWM2A, 2);
sprintf(placer, "WM2P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m2 term, phase", placer, PRPARAMS+disk*NDPARAMS+PWM2P, 2);
sprintf(placer, "WM3A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m3 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PWM3A, 2);
sprintf(placer, "WM3P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m3 term, phase", placer, PRPARAMS+disk*NDPARAMS+PWM3P, 2);
sprintf(placer, "WM4A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m4 term, amp ", placer, PRPARAMS+disk*NDPARAMS+PWM4A, 2);
sprintf(placer, "WM4P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give warp m4 term, phase", placer, PRPARAMS+disk*NDPARAMS+PWM4P, 2);
sprintf(placer, "LS0_%i=" , disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give S0 lopsided term", placer, PRPARAMS+disk*NDPARAMS+PLS0, 2);
sprintf(placer, "LC0_%i=" , disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give C0 lopsided term", placer, PRPARAMS+disk*NDPARAMS+PLC0, 2);
sprintf(placer, "Z0_%i=" , disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give scale-height (Z0) of rings. (arcsec)", placer, PRPARAMS+disk*NDPARAMS+PZ0, 2);
sprintf(placer, "SBR_%i=" , disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface-brightness of rings. (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PSBR, 2);
sprintf(placer, "SM1A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m1 term, amp (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PSM1A, 2);
sprintf(placer, "SM1P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m1 term, phase (deg)", placer, PRPARAMS+disk*NDPARAMS+PSM1P, 2);
sprintf(placer, "SM2A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m2 term, amp (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PSM2A, 2);
sprintf(placer, "SM2P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m2 term, phase (deg)", placer, PRPARAMS+disk*NDPARAMS+PSM2P, 2);
sprintf(placer, "SM3A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m3 term, amp (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PSM3A, 2);
sprintf(placer, "SM3P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m3 term, phase (deg)", placer, PRPARAMS+disk*NDPARAMS+PSM3P, 2);
sprintf(placer, "SM4A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m4 term, amp (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PSM4A, 2);
sprintf(placer, "SM4P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give surface brightness m4 term, phase (deg)", placer, PRPARAMS+disk*NDPARAMS+PSM4P, 2);
sprintf(placer, "GA1A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 1 (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PGA1A, 2);
sprintf(placer, "GA1P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 1 (deg)", placer, PRPARAMS+disk*NDPARAMS+PGA1P, 2);
sprintf(placer, "GA1D_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 1 (arcsec)", placer, PRPARAMS+disk*NDPARAMS+PGA1D, 2);
sprintf(placer, "GA2A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 2 (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PGA2A, 2);
sprintf(placer, "GA2P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 2 (deg)", placer, PRPARAMS+disk*NDPARAMS+PGA2P, 2);
sprintf(placer, "GA2D_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 2 (arcsec)", placer, PRPARAMS+disk*NDPARAMS+PGA2D, 2);
sprintf(placer, "GA3A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 3 (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PGA3A, 2);
sprintf(placer, "GA3P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 3 (deg)", placer, PRPARAMS+disk*NDPARAMS+PGA3P, 2);
sprintf(placer, "GA3D_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 3 (arcsec)", placer, PRPARAMS+disk*NDPARAMS+PGA3D, 2);
sprintf(placer, "GA4A_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give peak surface brigtness for Gaussian 4 (Jy/(arcsec*arcsec))", placer, PRPARAMS+disk*NDPARAMS+PGA4A, 2);
sprintf(placer, "GA4P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of Gaussian 4 (deg)", placer, PRPARAMS+disk*NDPARAMS+PGA4P, 2);
sprintf(placer, "GA4D_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give dispersion of Gaussian 4 (arcsec)", placer, PRPARAMS+disk*NDPARAMS+PGA4D, 2);
sprintf(placer, "AZ1P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of simulted range 1 (deg)", placer, PRPARAMS+disk*NDPARAMS+PAZ1P, 2);
sprintf(placer, "AZ1W_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give width of simulted range 1 (deg)", placer, PRPARAMS+disk*NDPARAMS+PAZ1W, 2);
sprintf(placer, "AZ2P_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give azimuth of simulted range 2 (deg)", placer, PRPARAMS+disk*NDPARAMS+PAZ2P, 2);
sprintf(placer, "AZ2W_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give width of simulted range 2 (deg)", placer, PRPARAMS+disk*NDPARAMS+PAZ2W, 2);
sprintf(placer, "INCL_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give inclinations of rings. (degrees)", placer, PRPARAMS+disk*NDPARAMS+PINCL, 2);
sprintf(placer, "PA_%i=" , disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give position angle of rings. (degrees)", placer, PRPARAMS+disk*NDPARAMS+PPA, 2);
sprintf(placer, "XPOS_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give Right Ascensions of ring centres. (degrees)", placer, PRPARAMS+disk*NDPARAMS+PXPOS, 2);
sprintf(placer, "YPOS_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give Declinations of ring centres. (degrees)", placer, PRPARAMS+disk*NDPARAMS+PYPOS, 2);
sprintf(placer, "VSYS_%i=", disk+1);get_parameter_double(startinfv, log, hdr, rpm, "Give systemic velocities of rings in (km/s).", placer, PRPARAMS+disk*NDPARAMS+PVSYS, 2);
}
/* Now, we have to convert the triplets into internal units */
for (disk = 0; disk < rpm -> ndisks; ++disk){
for (i = 0; i < rpm -> nur; ++i) {
globin[0] = rpm -> par[(PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nur+i];
globin[1] = rpm -> par[(PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nur+i];
globin[2] = rpm -> par[(PRPARAMS+disk*NDPARAMS+PVSYS)*rpm -> nur+i];
globtointern(globin, globout, hdr);
rpm -> par[(PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nur+i] = globout[0];
rpm -> par[(PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nur+i] = globout[1];
rpm -> par[(PRPARAMS+disk*NDPARAMS+PVSYS)*rpm -> nur+i] = globout[2];
}
}
/* Global velocity dispersion */
/* Default */
def = 0;
sprintf(mes, "Give global velicity dipersion (km/s)");
nel = 1;
/* this is variable with disk */
pcondisp = (NPARAMS + (rpm -> ndisks - 1)*NDPARAMS);
condisp = pcondisp+1;
/* This is the ninth parameter sequence */
if (!startinfv -> firstrun) {
cancel_tir(startinfv -> arel, "CONDISP=", 0);
}
userdble_tir(startinfv -> arel, rpm -> par+(pcondisp)*rpm -> nur, &nel, &def, "CONDISP=", mes);
/* it should be positive */
while (rpm -> par[(pcondisp)*rpm -> nur] < 0) {
sprintf(mes, "Negative velocity dispersion not allowed.");
cancel_tir(startinfv -> arel, "CONDISP", 2);
userdble_tir(startinfv -> arel, rpm -> par+(pcondisp)*rpm -> nur, &nel, &def, "CONDISP=", mes);
}
/* Change the value to grid units */
rpm -> par[(pcondisp)*rpm ->nur] = dparamtointern(rpm -> par[(pcondisp)*rpm ->nur], condisp, hdr, rpm -> ndisks);
/* The layer type */
rpm -> ltype[0] = 0;
def = 5;
sprintf(mes, "Give type of layer. [list options]");
nel = 1;
if (!startinfv -> firstrun) {
cancel_tir(startinfv -> arel, "LTYPE=", 0);
}
while(!rpm -> ltype[0]) {
userint_tir(startinfv -> arel, rpm -> ltype+0, &nel, &def, "LTYPE=", mes);
if((rpm -> ltype[0]) < 1 || (rpm -> ltype[0] > 5)) {
rpm -> ltype[0] = 0;
anyout_tir(rpm -> ltype+0, " Ltype:");
anyout_tir(rpm -> ltype+0, " 1 -- Gaussian layer");
anyout_tir(rpm -> ltype+0, " 2 -- Sech2 layer");
anyout_tir(rpm -> ltype+0, " 3 -- Exponential layer");
anyout_tir(rpm -> ltype+0, " 4 -- Lorentzian layer");
anyout_tir(rpm -> ltype+0, " 5 -- Box layer");
cancel_tir(startinfv -> arel, "LTYPE=", 2);
}
}
/* Do this ndisks-1 times more */
for (i = 1; i < rpm -> ndisks; ++i) {
sprintf(placer, "LTYPE_%i=", i+1);
if (!startinfv -> firstrun) {
cancel_tir(startinfv -> arel, placer, 0);
}
/* The layer type */
rpm -> ltype[i] = rpm -> ltype[i-1];
def = 2;
sprintf(mes, "Give type of layer %i. [list options]", i+1);
nel = 1;
dummy = 0;
while(!(dummy)) {
userint_tir(startinfv -> arel, rpm -> ltype+i, &nel, &def, placer, mes);
dummy = 1;
if((rpm -> ltype[i]) < 1 || (rpm -> ltype[i] > 5)) {
def = 5;
dummy = 0;
anyout_tir(rpm -> ltype+i, " Ltype:");
anyout_tir(rpm -> ltype+i, " 1 -- Gaussian layer");
anyout_tir(rpm -> ltype+i, " 2 -- Sech2 layer");
anyout_tir(rpm -> ltype+i, " 3 -- Exponential layer");
anyout_tir(rpm -> ltype+i, " 4 -- Lorentzian layer");
anyout_tir(rpm -> ltype+i, " 5 -- Box layer");
cancel_tir(startinfv -> arel, placer, 2);
}
}
}
/* cloud flux */
rpm -> cflux[0] = 1e-5;
def = 5;
sprintf(mes,"Cloud flux in (Jy*km/s) [1E-5]");
nel = 1;
if (!startinfv -> firstrun) {
cancel_tir(startinfv -> arel, "CFLUX=", 0);
}
userdble_tir(startinfv -> arel, rpm -> cflux+0, &nel, &def, "CFLUX=", mes);
while (rpm ->cflux[0] <= 0) {
sprintf(mes,"CFLUX must be greater than zero.");
rpm -> cflux[0] = 1e-5;
cancel_tir(startinfv -> arel, "CFLUX=", 2);
userdble_tir(startinfv -> arel, rpm -> cflux+0, &nel, &def, "CFLUX=", mes);
}
for (i = 1; i < rpm -> ndisks; ++i) {
sprintf(placer, "CFLUX_%i=", i+1);
if (!startinfv -> firstrun) {
cancel_tir(startinfv -> arel, placer, 0);
}
rpm -> cflux[i] = rpm -> cflux[i-1];
def = 2;
sprintf(mes,"Cloud flux (%i) in (Jy*km/s) [1E-5]", i+1);
nel = 1;
userdble_tir(startinfv -> arel, rpm -> cflux+i, &nel, &def, placer, mes);
while (rpm ->cflux[i] <= 0) {
def = 5;
sprintf(mes,"CFLUX must be greater than zero.");
rpm -> cflux[i] = 1e-5;
cancel_tir(startinfv -> arel, placer, 2);
userdble_tir(startinfv -> arel, rpm -> cflux+i, &nel, &def, placer, mes);
}
}
/* Initialise the io */
/* Now initialise the chisquare derivation (convolution) routines */
if (startinfv -> firstrun) {
/* Input noiseweight */
rpm -> weight = 1.0;
def = 5;
sprintf(mes, "Give noise weighting (0.0 means inf). [%f]", rpm -> weight);
nel = 1;
userreal_tir(startinfv -> arel, &rpm -> weight, &nel, &def, "WEIGHT=", mes);
/* Input PENALTY */
rpm -> penalty = 1.0;
def = 2;
sprintf(mes, "Give Penalty for outlyers [%f]", rpm -> penalty);
nel = 1;
userdble_tir(startinfv -> arel, &rpm -> penalty, &nel, &def, "PENALTY=", mes);
/* Now we recalculate the penalty */
rpm -> penalty = rpm -> cflux[0]*rpm -> penalty*SQRTOFPIHALF*((double) hdr -> bmaj)*((double) hdr -> bmaj)*((double) hdr -> bmin)*((double) hdr -> bmin)*HPBWTOSIGMATOFORTH/((double)(hdr -> rms*hdr -> rms));
/* Input inimode */
rpm -> inimode = 1;
def = 5;
#ifdef PBCORR
/* Primary beam correction */
def = 2;
nel = 1;
pbtel = 0;
userint_tir(startinfv -> arel, &pbtel, &nel, &def, "PBTEL=", mes);
/* We only take action if something gets specified */
if ((pbtel > 0) && (pbtel <= PBNTELS)) {
if (!(hdr -> primbeam = (float *) malloc(hdr -> bsize1*hdr -> bsize2*sizeof(float)))) {
anyout_tir(&dev, "Not enough memory");
goto error;
}
/* Ask for reference pixel and frequency */
sprintf(mes, "Give pbc reference pixel, starting at 0 0 in the lower left corner [centre]");
pbrefpix[0] = hdr -> bsize1/2-0.5;
pbrefpix[1] = hdr -> bsize2/2-0.5;
def = 2;
nel = 2;
userdble_tir(startinfv -> arel, pbrefpix, &nel, &def, "PBREFPIX=", mes);
/* Ask for reference frequency */
sprintf(mes, "Give pbc reference frequency (GHz) [1.4]");
pbreffreq = HIRESFREQ*1.0E-9;
def = 2;
nel = 2;
err = 1;
userdble_tir(startinfv -> arel, &pbreffreq, &nel, &def, "PBREFFREQ=", mes);
switch(pbtel) {
case PBWSRT:
case PBWSRT_2:
while ((err)) {
if ((pbreffreq < 8) && (pbreffreq > 0.5)) {
--err;
}
else {
def = 1;
anyout_tir(&dev, "Must lie between 0.5 and 8.0");
cancel_tir(startinfv -> arel, "PBREFFREQ=", 2);
pbreffreq = HIRESFREQ*1.0E-9;
userdble_tir(startinfv -> arel, &pbreffreq, &nel, &def, "PBREFFREQ=", mes);
}
}
break;
default:
;
}
switch(pbtel) {
case PBWSRT:
case PBWSRT_2:
/* (cos((pi/180)*c * nu/GHz * r/deg ))^6, c = 60.7492, (cos(c1* nu/GHz * r/deg))^6, c1 = 1.0602735280990601 (estimated from HPBW in Miriad), nu: frequency in GHz, r: radius in deg */
/* hdr -> deltgridtouser[0,1] gives conversion from pixel to arcsec */
/* rp = sqrt((x-refpixx)^2+(y-refpixy)^2): radius in pixel */
/* r = sqrt(((x-refpixx)*hdr->deltgridtouser[0])^2+((y-refpixy)*hdr->deltgridtouser[1])^2)/3600.0 */
/* neclecting the frequency dependency results in an error of 1-2/1000 at half power. The uncertainty in the parameters is much larger */
/* An experiment shows that this conforms with the miriad primary beam correction for the WSRT at a level of 0.002 percent, so to float precision level */
/* A communication with T.A. results in the fact that one should use c = 68 instead. Details are here: Popping & Braun 2008, A&A 479, 903 */
switch(pbtel) {
case PBWSRT:
pbwsrtconst = PBWSRTCONST_1;
break;
case PBWSRT_2:
pbwsrtconst = PBWSRTCONST_2;
break;
}
for (i = 0; i < hdr -> bsize1; ++i) {
#ifdef OPENMPTIR
#pragma omp parallel for private(pbdoublev1,pbdoublev2,pbradius)
#endif
for (j = 0; j < hdr -> bsize2; ++j) {
pbdoublev1 = (((double) i)-pbrefpix[0])*hdr->deltgridtouser[0];
pbdoublev2 = (((double) j)-pbrefpix[1])*hdr->deltgridtouser[1];
pbradius = (pbwsrtconst*pbreffreq*sqrt(pbdoublev1*pbdoublev1+pbdoublev2*pbdoublev2));
if (pbradius < PIHALF)
hdr -> primbeam[i+hdr -> bsize1*j] = pow(cos(pbradius),6);
else
hdr -> primbeam[i+hdr -> bsize1*j] = 0.0;
}
}
break;
default:
break;
}
}
/* Now arrange for the correct links */
chkb_pbcorr(hdr, rpm);
#endif
sprintf(mes, "Give initialisation time 0 short, 3 long [1]");
nel = 1;
err = 0;
while (!(err)) {
userint_tir(startinfv -> arel, &(rpm -> inimode), &nel, &def, "INIMODE=", mes);
if (rpm -> inimode < 0 || rpm -> inimode > 3) {
sprintf(mes, "Out of range %i", rpm -> inimode);
cancel_tir(startinfv -> arel, "INIMODE=", 2);
rpm -> inimode = 1;
def = 5;
}
else
err = 1;
}
/* Input mode */
rpm -> mode = 3;
def = 5;
/* sprintf(mes, "Give memory consumption mode. [list options]"); */
/* nel = 1; */
/* i = 0; */
/* while (!(i)) { */
/* userint_tir(&rpm -> mode, &nel, &def, "MEMMODE=", mes); */
/* if (rpm -> mode < 0 || rpm -> mode > 3) { */
/* anyout_tir(&i, " MemMode:"); */
/* anyout_tir(&i, " 0 -- in-place, no boost."); */
/* anyout_tir(&i, " 1 -- in-place, using boost."); */
/* anyout_tir(&i, " 2 -- out-place, no boost."); */
/* anyout_tir(&i, " 3 -- out-place, using boost."); */
/* cancel_tir(startinfv -> arel, "MEMMODE="); */
/* rpm -> mode = 3; */
/* def = 5; */
/* } */
/* else */
/* i = 1; */
/* } */
mode = rpm -> mode*2;
if ((rpm -> weight))
++mode;
/* sprintf(obsmes, */
/* "ori[0]: %f\n" */
/* "model[0]: %f\n" */
/* "bsize1: %i\n" */
/* "bsize2: %i\n" */
/* "nsubs: %i\n" */
/* "bmaj: %f\n" */
/* "bmin: %f\n" */
/* "bpa: %f\n" */
/* "cflux[0]: %f\n" */
/* "rms: %f\n" */
/* "mode: %i\n" */
/* "2*(bsize1/2+1): %i\n" */
/* "chi2 (random): %f\n" */
/* "weight: %f\n" */
/* "inimode: %i\n" */
/* "ncores: %i\n", */
/* hdr -> oric -> points[0], hdr -> modelc -> points[0], hdr -> bsize1, hdr -> bsize2, hdr -> nsubs, hdr -> bmaj, hdr -> bmin, hdr -> bpa, rpm -> cflux[0], hdr -> rms, mode, 2*(hdr -> bsize1/2+1), hdr -> chi2, rpm -> weight, rpm -> inimode, log -> ncores */
/* ); */
/* anyout_tir(&obsint, obsmes); */
/* Try to initialise the chisquare machinery */
while (mode >= 0 && mode < 8) {
if (!initchisquare_c(hdr -> oric -> points, hdr -> modelc -> points, hdr -> bsize1, hdr -> bsize2, hdr -> nsubs, hdr -> bmaj, hdr -> bmin, hdr -> bpa, 1, rpm -> cflux[0], hdr -> rms, mode, 2*(hdr -> bsize1/2+1), &hdr -> chi2, rpm -> weight, rpm -> inimode, log -> ncores)) {
mode = mode-2;
j = 0;
}
else {
mode = 8;
}
}
j = 4;
if (mode < 8)
error_tir(&j,"Error initializing chi^2 derivation control.");
/* Write inset data into ori array (has been done since long)*/
/* nel = 0; */
/* def = 4; */
/* for (i = 0; i < hdr -> nsubs; ++i) { */
/* j=i*hdr -> nprof; */
/* gdsi_read_tir(hdr -> inset, hdr -> cwlo+i, hdr -> cwhi+i, hdr -> ori+j, &hdr -> nprof, &k, &nel); */
/* if ((nel)) { */
/* error_tir(&def, "Unable to read inset."); */
/* } */
/* } */
/* close inset (not needed anymore ?) */
/* gds_close_tir(hdr -> inset, &def); */
/* Now the cube has to be rearranged, because it is padded */
/* for(k = hdr -> nsubs-1; k >= 0; --k) { */
/* for(j = hdr -> bsize2-1; j >= 0; --j) { */
/* for(i = hdr -> bsize1-1; i >= 0; --i) { */
/* hdr -> ori[i+2*(hdr -> bsize1/2+1)*(j+hdr -> bsize2*k)] = hdr -> ori[i+hdr -> bsize1*(j+hdr -> bsize2*k)]; */
/* } */
/* } */
/* } */
/* The cube has changed, therefore we need to do this */
engalmod_chflgs();
/* Also, we change the nprof */
hdr -> nprof = hdr -> bcsize1*hdr -> bsize2;
/* We initialise the sd array */
for (i = 0; i < rpm -> ndisks; ++i) {
if (!(rpm -> sd[i] = create_srd(rpm -> nr)))
goto error;
for (j = 0; j < rpm -> nr; ++j) {
if (!(rpm -> sd[i][j].permrandstr = (maths_rstrf *) malloc(sizeof(maths_rstrf))))
goto error;
rpm -> sd[i][j].randstr = NULL;
rpm -> sd[i][j].grandstr[0] = NULL;
rpm -> sd[i][j].grandstr[1] = NULL;
rpm -> sd[i][j].grandstr[2] = NULL;
rpm -> sd[i][j].grandstr[3] = NULL;
rpm -> sd[i][j].srandstr = NULL;
}
}
}
/* Get the info for the single-model random-number generator */
/* First from the log if present */
rpm -> iseed2 = 1803;
def = 2;
sprintf(mes, "Give one integer to initialize RNG. [1803]");
if (!startinfv -> firstrun)
cancel_tir(startinfv -> arel, "ISEED=", 0);
nel = 1;
userint_tir(startinfv -> arel, &rpm -> iseed2, &nel, &def, "ISEED=", mes);
while (rpm -> iseed2 < 0 || rpm -> iseed2 > 31328) {
sprintf(mes, "Iseed out of range.");
cancel_tir(startinfv -> arel, "ISEED=", 2);
def = 5;
userint_tir(startinfv -> arel, &rpm -> iseed2, &nel, &def, "ISEED=", mes);
}
for (i = 0; i < rpm -> ndisks; ++i) {
for (j = 0; j < rpm -> nr; ++j) {
rpm -> sd[i][j].iseed2[0] = rpm -> iseed2;
}
}
return rpm;
error:
destroy_ringparms(rpm);
if (hdr)
destroy_hdrinf(hdr);
if (log)
destroy_loginf(log, rpm -> ndisks);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a fitparms structure */
static fitparms *create_fitparms(ringparms *rpm)
{
fitparms *fit;
if (!(fit = (fitparms *) malloc(sizeof(fitparms))))
return NULL;
fit -> varylist = NULL;
fit -> normrandstr = NULL;
fit -> gft_mstv = NULL;
fit -> varyhstr = NULL;
fit -> index = NULL;
fit -> mon_dpar = NULL;
fit -> reg_contv = NULL;
fit -> npoints = NULL;
/* Allocate the memory */
if (!(fit -> normrandstr = (maths_rstr *) malloc(sizeof(maths_rstr))))
goto error;
if (!(fit -> npoints = (int *) malloc(rpm -> ndisks*sizeof(int))))
goto error;
if (!(fit -> fluxpoints = (long *) malloc(rpm -> ndisks*sizeof(long))))
goto error;
if (!(fit -> mon_repnpoints = (int *) malloc(rpm -> ndisks*sizeof(int))))
goto error;
if (!(fit -> mon_totalflux = (double *) malloc(rpm -> ndisks*sizeof(double))))
goto error;
return fit;
error:
destroy_fitparms(fit);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Destroys a fitparms structure */
void destroy_fitparms(fitparms *fit)
{
/* Check if it is there */
if (!(fit))
return;
if ((fit -> varylist))
destroyvarlel(fit -> varylist);
if((fit -> normrandstr))
free(fit -> normrandstr);
if((fit -> npoints))
free(fit -> npoints);
if((fit -> fluxpoints))
free(fit -> fluxpoints);
if((fit -> mon_repnpoints))
free(fit -> mon_repnpoints);
if((fit -> mon_totalflux))
free(fit -> mon_totalflux);
if((fit -> gft_mstv))
gft_mst_destr(fit -> gft_mstv);
if((fit -> varyhstr))
free(fit -> varyhstr);
if((fit -> mon_dpar))
free(fit -> mon_dpar);
if((fit -> index))
decomp_inlist_dest(fit->index);
if ((fit -> reg_contv))
reg_cont_destr(fit -> reg_contv);
if ((fit -> adar))
free(fit -> adar);
free(fit);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Fill the fitparms struct from the input */
static fitparms *get_fitparms(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fitparmsv)
{
fitparms *fit;
/* Private control and changing variables */
int def; /* Any default mode */
int nel; /* Number of elements */
int nread; /* Number of read elements */
char mes[81]; /* Any message */
int errcode = 1; /* another error code */
int anint;
int i, j, k; /* Simple control variables */
/* Private input lists */
varlel **pointarray = NULL;
double *parmax = NULL;
double *parmin = NULL;
int *moderate = NULL;
double *delstart = NULL;
double *delend = NULL;
int *itestart = NULL;
int *iteend = NULL;
double *satdelt = NULL;
double *mindelta = NULL;
char *varyhstr = NULL;
char **varystr= NULL; /* An array of short strings to hold some input strings */
char **inputofvarysing = NULL;
char **inputofvarymult = NULL;
char *dcperr;
decomp_control decomp_controlv = NULL;
decomp_listel *decomp_listelv = NULL;
inlistel *flistel = NULL;
varlel *varele;
varlel *varylist = NULL;
size_t size_tv; /* dummy */
/* diverse */
adar *adarv = NULL;
double *array = NULL; /* An array to contain a row */
/* arel output */
int nreadl, nreturned, keypres;
int neill;
/* Get the struct */
if (!startinfv -> firstrun) {
destroy_fitparms(fitparmsv);
/* These are all the parameters that need to be re-read */
cancel_tir(startinfv -> arel, "FITMODE=", 0);
cancel_tir(startinfv -> arel, "LOOPS=", 0);
cancel_tir(startinfv -> arel, "MAXITER=", 0);
cancel_tir(startinfv -> arel, "CALLITE=", 0);
cancel_tir(startinfv -> arel, "SIZE=", 0);
cancel_tir(startinfv -> arel, "PSSE=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSNP=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSCO=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSSO=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSMV=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSNF=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSIW=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSFW=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSID=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "PSDD=", 0); /* only fitmode = PSWARM */
cancel_tir(startinfv -> arel, "VARINDX=", 0);
cancel_tir(startinfv -> arel, "VARY=", 0);
cancel_tir(startinfv -> arel, "VARYSING=", 0);
cancel_tir(startinfv -> arel, "VARYMULT=", 0);
cancel_tir(startinfv -> arel, "PARMAX=", 0);
cancel_tir(startinfv -> arel, "PARMIN=", 0);
cancel_tir(startinfv -> arel, "MODERATE=", 0);
cancel_tir(startinfv -> arel, "DELSTART=", 0);
cancel_tir(startinfv -> arel, "DELEND=", 0);
cancel_tir(startinfv -> arel, "ITESTART=", 0); /* (only fitmode = golden section) */
cancel_tir(startinfv -> arel, "ITEEND=", 0); /* (only fitmode = golden section) */
cancel_tir(startinfv -> arel, "MINDELTA=", 0);
}
if (!(fit = create_fitparms(rpm))) {
goto error;
}
/* Input fitmode */
fit -> fitmode = 2;
def = 1;
sprintf(mes, "Give fitting mode 2: golden section, 3: simplex [2]");
nel = 1;
userint_tir(startinfv -> arel, &fit -> fitmode, &nel, &def, "FITMODE=", mes);
if ((fit -> fitmode == METROPOLIS)) {
sprintf(mes, "Method not existent (currently no Metropolis)");
anyout_tir(&def, mes);
goto error;
}
/* now we plug in the next generation fit codes */
if (fit -> fitmode > 1) {
/* Allocate the fit control object */
if (!(fit -> gft_mstv = gft_mst_const()))
goto error;
/* Try to specify method */
i = fit -> fitmode-1;
if ((j = gft_mst_put(fit -> gft_mstv, &i, GFT_INPUT_METHOD))) {
if (j & 64) {
def = 1;
sprintf(mes, "Method not existent");
anyout_tir(&def, mes);
goto error;
}
}
gft_mst_putf(fit -> gft_mstv, &gchsq_gen_start, GFT_INPUT_GCHSQ);
/* Try to allocate the arguments struct and link */
if (!(adarv = (adar *) malloc(sizeof(adar))))
goto error;
fit -> adar = (void *) adarv;
adarv -> startinfv = startinfv;
adarv -> log = log;
adarv -> hdr = hdr;
adarv -> rpm = rpm;
adarv -> fit = fit;
/* Pack it into gft */
gft_mst_put(fit -> gft_mstv, fit -> adar, GFT_INPUT_ADAR);
}
/* Input loops */
fit -> loops = 500000;
def = 1;
sprintf(mes, "Give number of loops to process. [500000]");
nel = 1;
userint_tir(startinfv -> arel, &fit -> loops, &nel, &def, "LOOPS=", mes);
/* Get the total maximum number of iterations */
if (fit -> fitmode > GOLDEN_SECTION) {
fit -> maxiter = 5000000;
def = 1;
sprintf(mes, "Give maximum number of total iterations. [5000000]");
nel = 1;
userint_tir(startinfv -> arel, &fit -> maxiter, &nel, &def, "MAXITER=", mes);
fit -> callite = 5000000;
def = 1;
sprintf(mes, "Give maximum number of steps per iteration. [5000000]");
nel = 1;
userint_tir(startinfv -> arel, &fit -> callite, &nel, &def, "CALLITE=", mes);
fit -> size = 1.0;
def = 1;
sprintf(mes, "Give stop size relative to minsteps. [1.0]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> size, &nel, &def, "SIZE=", mes);
}
/* in case of PSWARM, we need these here, again propagating the defaults */
if (fit -> fitmode == PSWARM) {
fit -> psse = PSW_PSSE_DEF;
def = 2;
sprintf(mes, "Give seed for PSWARM rng. [42]");
nel = 1;
userint_tir(startinfv -> arel, &fit -> psse, &nel, &def, "PSSE=", mes);
fit -> psnp = PSW_PSNP_DEF;
def = 2;
sprintf(mes, "Give swarm size for PSWARM. [42]");
nel = 1;
userint_tir(startinfv -> arel, &fit -> psnp, &nel, &def, "PSNP=", mes);
fit -> psco = PSW_PSCO_DEF;
def = 2;
sprintf(mes, "Give cognition parameter for PSWARM. [0.5]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> psco, &nel, &def, "PSCO=", mes);
fit -> psso = PSW_PSSO_DEF;
def = 2;
sprintf(mes, "Give social parameter for PSWARM. [0.5]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> psso, &nel, &def, "PSSO=", mes);
fit -> psmv = PSW_PSMV_DEF;
def = 2;
sprintf(mes, "Give maximum velocity for PSWARM. [1.0]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> psmv, &nel, &def, "PSMV=", mes);
fit -> psnf = PSW_PSNF_DEF;
def = 2;
sprintf(mes, "Number of Evaluations from initial inertia to final inertia for PSWARM. [8000]");
nel = 1;
userint_tir(startinfv -> arel, &fit -> psnf, &nel, &def, "PSNF=", mes);
fit -> psii = PSW_PSII_DEF;
def = 2;
sprintf(mes, "Give initial inertia for PSWARM. [0.9]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> psii, &nel, &def, "PSII=", mes);
fit -> psfi = PSW_PSFI_DEF;
def = 2;
sprintf(mes, "Give final inertia for PSWARM. [0.4]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> psfi, &nel, &def, "PSFI=", mes);
fit -> psid = PSW_PSID_DEF;
def = 2;
sprintf(mes, "Give increase factor for delta for grid search. [2.0]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> psid, &nel, &def, "PSID=", mes);
fit -> psdd = PSW_PSDD_DEF;
def = 2;
sprintf(mes, "Give decrease factor for delta for grid search. [2.0]");
nel = 1;
userdble_tir(startinfv -> arel, &fit -> psdd, &nel, &def, "PSDD=", mes);
}
/* We are through with the first hdu, so it will be created if not already existent */
/******************/
/******************/
/* This was commented hdu stuff */
/* if ((log -> logname) && (log -> logpres)) { */
/* if ((create_hdu_1(log, hdr, rpm, fit))) */
/* goto error; */
/* } */
/* ftstab_close_(); */
/******************/
/******************/
/* Make a flush and don't forget to recreate the hdrlist */
/* ftstab_flush_(); */
/* ftstab_hdlreset_(); */
/* hdl_init(); */
/* Now open the second hdu, if possible and if we expect one */
/* if ((log -> logname) && !(log -> logpres)) { */
/* Try to open the file to check if it is already present */
/* log -> logpres = ftstab_fopen(log -> logname, 2, 2, 1); */
/* Furthermore we will simply overwrite the extension */
/* ftstab_close_(); */
/* ftstab_flush_(); */
/* ftstab_hdlreset_(); */
/* hdl_init(); */
/* log -> logpres = 1; */
/* } */
/*****************************/
/******* new way to read parameters ********/
/*****************************/
/* The complicated varystr */
/* Finally, no static arrays any more */
/* if (!(varystr = (char **) malloc(VARYSTRELES*sizeof(char *)))) */
/* goto error; */
/* if (!(varyhstr = getfcharray(VARYHSTRELES, NULL))) */
/* goto error; */
/* get the dcp control structure */
if (!(decomp_controlv = decomp_init()))
goto error;
/* Fill the dcp control structure with parameter information */
if ((dec_fill(rpm, decomp_controlv)))
goto error;
/* Now get the indexed parameters, for that we know only one group */
decomp_putsep(decomp_controlv, '\0', '\0', ':');
errcode = 2;
/* Get the index array */
neill = 0;
while (errcode) {
def = 1;
/* nel = usertext_tir(varyhstr, &def, "VARINDX=",mes); */
/* varyhstr[nel] = '\0'; */
if (simparse_scn_arel_readval_string(startinfv -> arel, "VARINDX", "Give fitting index.", 0, "", 0, -1, neill, 0, &keypres, &nreadl, &nreturned, &varyhstr)) {
goto error;
}
/* Interlude: Change the case if it is lower case */
i = 0;
while (varyhstr[i]) {
if (varyhstr[i] >= 'a' && varyhstr[i] <= 'z')
varyhstr[i] = varyhstr[i]+'A'-'a';
++i;
}
/* Interpret this */
if ((errcode = decomp_get(decomp_controlv, varyhstr, &decomp_listelv, 0))){
if (errcode == 1)
goto error;
else {
sprintf(mes, "VARINDX: ");
if (decomp_errmsg(decomp_controlv))
strncpy(mes+9,decomp_errmsg(decomp_controlv),72);
cancel_tir(startinfv -> arel, "VARINDX=", 2);
printf("report err here\n");
anyout_tir(&def, mes);
printf("report err here\n");
neill = 1;
}
}
}
/* Now use this to prepare an index and change the input method */
decomp_index(decomp_controlv, (decomp_listelv) -> nuel, (decomp_listelv) -> poli);
/* Deallocate what we don't need anymore, or rather, again */
decomp_list_dest(decomp_listelv);
decomp_listelv = NULL;
errcode = 1;
k = 0;
/* Get the vary array */
neill = 0;
while (errcode) {
nel = 0;
def = 1;
if (errcode == 2)
cancel_tir(startinfv -> arel, "VARY=", 2);
sprintf(mes, "Give fit parameters");
if ((varyhstr))
free(varyhstr);
/* flushfcharray(VARYHSTRELES, varyhstr); */
/* nel = usertext_tir(varyhstr, &def, "VARY=", mes); */
if (simparse_scn_arel_readval_string(startinfv -> arel, "VARY", "Give fitting index.", 0, "", 0, -1, neill, 0, &keypres, &nreadl, &nreturned, &varyhstr)) {
goto error;
}
/* only if this is 0, we ask (completely hidden) for an input in the old style */
if (!strlen(varyhstr)) {
/* Read in and make a decomp-interpretable string of varysing and varymult */
nel = 0;
if ((errcode == 2) && (k == 1))
cancel_tir(startinfv -> arel, "VARYSING=", 2);
/* sprintf(mes, "Give fit parameters, single"); */
/* flushfcharray(VARYHSTRELES, varyhstr); */
/* nel = usertext_tir(varyhstr, &def, "VARYSING=",mes); */
if ((varyhstr)) {
free(varyhstr);
varyhstr = NULL;
}
if (simparse_scn_arel_readval_string(startinfv -> arel, "VARYSING", "Give fit parameters, single.", 0, "", 0, -1, 0, 0, &keypres, &nreadl, &nreturned, &varyhstr))
goto error;
if (!(inputofvarysing = sparsenext(" \t", "", "", "", "", "", -1, &varyhstr, &anint, 1, 1)))
goto error;
if (errcode == 2 && (k == 1))
cancel_tir(startinfv -> arel, "VARYMULT=", 2);
/* sprintf(mes, "Give fit parameters, multi"); */
/* flushfcharray(VARYHSTRELES, varyhstr); */
/* nel = usertext_tir(varyhstr, &def, "VARYMULT=",mes); */
/* varyhstr[nel] = '\0'; */
if ((varyhstr)) {
free(varyhstr);
varyhstr = NULL;
}
if (simparse_scn_arel_readval_string(startinfv -> arel, "VARYMULT", "Give fit parameters, multi.", 0, "", 0, -1, 0, 0, &keypres, &nreadl, &nreturned, &varyhstr))
goto error;
if (!(inputofvarymult = sparsenext(" \t", "", "", "", "", "", -1, &varyhstr, &anint, 1, 1)))
goto error;
/* flushfcharray(VARYHSTRELES, varyhstr); */
if ((varyhstr)) {
free(varyhstr);
varyhstr = NULL;
}
if (!(varyhstr = gluetodecomp(inputofvarymult, inputofvarysing)))
goto error;
if (inputofvarysing)
freeparsed(inputofvarysing);
inputofvarysing = NULL;
if (inputofvarymult)
freeparsed(inputofvarymult);
inputofvarymult = NULL;
k = 1;
}
/* Interlude: Change the case if it is lower case */
i = 0;
while (varyhstr[i]) {
if (varyhstr[i] >= 'a' && varyhstr[i] <= 'z')
varyhstr[i] = varyhstr[i]+'A'-'a';
++i;
}
decomp_putsep(decomp_controlv, ',', '!', ':');
/* Interpret this */
if ((errcode = decomp_get(decomp_controlv, varyhstr, &decomp_listelv, 0))){
if (errcode == 1)
goto error;
else {
sprintf(mes, "VARY (error also occurs for VARYSING and VARYMULT): ");
if ((dcperr = decomp_errmsg(decomp_controlv)))
strncpy(mes+6, dcperr, 74);
anyout_tir(&def, mes);
neill = 1;
}
}
}
/* We safe the varyhstr */
fit -> varyhstr = varyhstr;
varyhstr = NULL;
/* We create the index list */
if (!(fit -> index = decomp_inlist_init()))
goto error;
if ((neill = decomp_get_inlist(decomp_controlv, fit -> index))) {
if (neill == 2)
printf("Syntax error in VARINDX\n");
goto error;
}
/* Now that we have that array, we can get the other parameters, allocate space for that: count the numbers of parameters needed */
k = 0;
/* m = 0; */
if (decomp_listelv) {
i = 0;
while ((decomp_listelv+i) -> nuel != -1) {
k = (decomp_listelv+i) -> grnr+1;
++i;
}
}
if (varyhstr) {
free(varyhstr);
varyhstr = NULL;
}
/* I think this makes no sense, except to make it freeable at the end of this function */
/* if (!(varyhstr = getfcharray(VARYHSTRELES, NULL))) */
/* goto error; */
/* Do some allocations */
/* Allocate the pointarray */
if (!(pointarray = (varlel **) malloc(k*sizeof(varlel *))))
goto error;
/* Allocate the other stuff */
if (!(parmax = (double *) malloc(k*sizeof(double))))
goto error;
if (!(parmin = (double *) malloc(k*sizeof(double))))
goto error;
if (!(moderate = (int *) malloc(k*sizeof(int))))
goto error;
if (!(delstart = (double *) malloc(k*sizeof(double))))
goto error;
if (!(delend = (double *) malloc(k*sizeof(double))))
goto error;
if (!(itestart = (int *) malloc(k*sizeof(int))))
goto error;
if (!(iteend = (int *) malloc(k*sizeof(int))))
goto error;
if (!(satdelt = (double *) malloc(k*sizeof(double))))
goto error;
if (!(mindelta = (double *) malloc(k*sizeof(double))))
goto error;
/* Read in all the stuff from the logfile */
nel = k;
/* Create defaults for the case that the user is too lazy */
if (create_defaults_from_dcp(hdr, decomp_listelv, parmax, parmin, moderate, delstart, delend, itestart, iteend, satdelt, mindelta, rpm -> nur, rpm -> ndisks, fit -> fitmode))
goto error;
/* Now read in everything from the input */
/* Get the steps */
/* sprintf(mes, "Give maximal variation deltas (in the same order)"); */
/* def = 4; */
/* userdble_tir(startinfv -> arel, steps, &nel, &def, "STEPS=", mes); */
/* Now read in everything from the user input */
/* The default is +inf */
/* for (i = 0; i < k; ++i) { */
/* parmax[i] = DBL_MAX; */
/* parmin[i] = -DBL_MAX; */
/* moderate[i] = 0; */
/* } */
/* We have created defaults, and the user is allowed to make use of them, hence no longer def = 4, but def = 2 */
def = 2;
/* Get the parmax */
sprintf(mes, "Give parameter maximum (in the same order)");
userdble_tir(startinfv -> arel, parmax, &nel, &def, "PARMAX=", mes);
/* Get the parmin */
sprintf(mes, "Give parameter minimum (in the same order)");
userdble_tir(startinfv -> arel, parmin, &nel, &def, "PARMIN=", mes);
/* Get the moderating steps */
if (fit -> fitmode != PSWARM) {
sprintf(mes, "Give moderating steps (in the same order)");
userint_tir(startinfv -> arel, moderate, &nel, &def, "MODERATE=", mes);
/* I have no patience programming a warning. If a negative value is
given, it will be changed to positive */
for (i = 0; i < k; ++i) {
if (moderate[i] < 0)
moderate[i] = -moderate[i];
}
/* Get the start delta */
sprintf(mes, "Give the start delta (in the same order)");
userdble_tir(startinfv -> arel, delstart, &nel, &def, "DELSTART", mes);
/* Get the end delta */
/* No longer defaults to startdelta, but to defaults */
/* if (def == 5) { */
/* for (i = 0; i < k; ++i) */
/* delend[i] = delstart[i]; */
/* } */
sprintf(mes, "Give the end delta (in the same order)");
userdble_tir(startinfv -> arel, delend, &nel, &def, "DELEND", mes);
}
else {
for (i = 0; i < k; ++i) {
moderate[i] = 0;
}
}
/* These are not required for fitmode metropolis (which currently does not exist) */
if (fit -> fitmode >= GOLDEN_SECTION) {
/* Get the itestart */
/* defaul = defaul%4; */
if (fit -> fitmode == GOLDEN_SECTION) {
sprintf(mes, "Give starting number of iterations");
nread = userint_tir(startinfv -> arel, itestart, &nel, &def, "ITESTART", mes);
/* I have no patience programming a warning. If a negative value is
given, it will be changed to positive and 0 will be changed to 1 */
for (i = 0; i < k; ++i) {
if (itestart[i] < 0)
itestart[i] = -itestart[i];
if (itestart[i] == 0)
itestart[i] = 1;
if (i >= nread || fit -> fitmode > GOLDEN_SECTION) {
if (i > 0)
itestart[i] = itestart[i-1];
}
}
/* Get the iteend */
/* Defaults to itestart */
/* if (def%4 == 1) { */
/* for (i = 0; i < k; ++i) */
/* iteend[i] = itestart[i]; */
/* } */
/* def = def%4; */
sprintf(mes, "Give final number of iterations (in the same order)");
nread = userint_tir(startinfv -> arel, iteend, &nel, &def, "ITEEND", mes);
/* I have no patience programming a warning. If a negative value is
given, it will be changed to positive and 0 will be changed to 1 */
for (i = 0; i < k; ++i) {
if (iteend[i] < 0)
iteend[i] = -iteend[i];
if (iteend[i] == 1)
iteend[i] = 1;
if (i >= nread || fit -> fitmode > GOLDEN_SECTION) {
if (i > 0)
iteend[i] = iteend[i-1];
}
}
/* if (defaul != 2) */
/* defaul |= 4; */
/* if (def != 2) */
/* def |= 4; */
/* Get the satisfaction delta*/
sprintf(mes, "Give the satisfaction deltas (in the same order)");
userdble_tir(startinfv -> arel, satdelt, &nel, &def, "SATDELT=", mes);
/* dito */
for (i = 0; i < k; ++i) {
if (satdelt[i] < 0)
satdelt[i] = -satdelt[i];
}
}
else {
for (i = 0; i < k; ++i) {
itestart[i] = 0;
iteend[i] = 0;
satdelt[i] = 0.0;
}
}
/* if (defaul != 2) */
/* defaul |= 4; */
/* if (def != 2) */
/* def |= 4; */
/* Get the minimum deltas */
sprintf(mes, "Give the minimum deltas (in the same order)");
userdble_tir(startinfv -> arel, mindelta, &nel, &def, "MINDELTA=", mes);
/* dito */
for (i = 0; i < k; ++i) {
if (mindelta[i] < 0)
mindelta[i] = -mindelta[i];
}
}
/* else { */
/* for (i = 0; i < k; ++i) { */
/* mindelta[i] = 0.0; */
/* } */
/* } */
/* We create a varylist linked list from the input and link it into fit -> varylist */
/* ndisk construction */
/* The only possibility for an error is memory problems */
if (!(fit -> varylist = create_varylist_from_dcp(hdr, decomp_listelv, parmax, parmin, moderate, delstart, delend, itestart, iteend, satdelt, mindelta, rpm -> nur, rpm -> ndisks)))
goto error;
/* At the end we will check out and initialise certain behaviour dependent on the choice of parameters */
/* ndisk construction */
chkb_sdis(rpm,fit);
chkb_vrad(rpm,fit);
chkb_vver(rpm,fit);
chkb_dvro(rpm,fit);
chkb_dvra(rpm,fit);
chkb_dvve(rpm,fit);
chkb_vm0(rpm,fit);
chkb_vm1(rpm,fit);
chkb_vm2(rpm,fit);
chkb_vm3(rpm,fit);
chkb_vm4(rpm,fit);
chkb_ra1(rpm,fit);
chkb_ra2(rpm,fit);
chkb_ra3(rpm,fit);
chkb_ra4(rpm,fit);
chkb_ro1(rpm,fit);
chkb_ro2(rpm,fit);
chkb_ro3(rpm,fit);
chkb_ro4(rpm,fit);
chkb_wm0(rpm,fit);
chkb_wm1(rpm,fit);
chkb_wm2(rpm,fit);
chkb_wm3(rpm,fit);
chkb_wm4(rpm,fit);
chkb_ls0(rpm,fit);
chkb_lc0(rpm,fit);
chkb_smi(rpm,fit);
chkb_gau(rpm,fit);
chkb_azi(rpm,fit);
/* These are now not necessary anymore, they exist in any case */
free(parmax);
parmax = NULL;
free(parmin);
parmin = NULL;
free(moderate);
moderate = NULL;
free(delstart);
delstart = NULL;
free(delend);
delend = NULL;
free(itestart);
itestart = NULL;
free(iteend);
iteend = NULL;
free(satdelt);
satdelt = NULL;
free(mindelta);
mindelta = NULL;
if (array)
free(array);
array = NULL;
/* Now write the second hdu if warranted */
/* We are thru with the second hdu, so it will be created if not already existent */
/******************/
/******************/
/* This was commented hdu stuff */
/* if ((log -> logname) && (log -> logpres)) { */
/* if ((create_hdu_2(log -> logname, fit -> varylist, pointarray, rpm -> nur, hdr))) */
/* goto error; */
/* } */
/* ftstab_close_(); */
/* Make a flush and don't forget to recreate the hdrlist */
/* ftstab_flush_(); */
/* ftstab_hdlreset_(); */
/* hdl_init(); */
/* Calculate degrees of freedom here */
/* Count the number of parameters and put them in */
varele = fit -> varylist;
i = 0;
while (varele) {
++i;
varele = varele -> next;
}
fit -> dof = ((double) (hdr -> bsize1*hdr -> bsize2*hdr -> nsubs)/(CONVTHREEDBEAM*hdr -> bmaj*hdr -> bmin))-((double) i);
/* Now make the arrangements for the minimiser */
if (fit -> fitmode > GOLDEN_SECTION) {
/* Count the number of parameters and put them in */
varele = fit -> varylist;
i = 0;
while (varele) {
++i;
varele = varele -> next;
}
fit -> mon_npar = i;
size_tv = i;
gft_mst_put(fit -> gft_mstv, &size_tv, GFT_INPUT_NPAR);
/* Allocate the mon_dpar array and initialise */
if (!i)
++i;
if (!(fit -> mon_dpar = (double *) malloc (i*sizeof(double))))
goto error;
fit -> mon_dpar[0] = 0.0;
/* Allocate a double array for generic use */
/* if (!(array = (double *) malloc (i*sizeof(double)))) */
/* goto error; */
/* Now put in the start parameters, is done in genfit */
/* i = 0; */
/* varele = fit -> varylist; */
/* while (varele) { */
/* array[i] = rpm -> par[varele -> elements[0]]; */
/* ++i; */
/* varele = varele -> next; */
/* } */
/* gft_mst_put(fit -> gft_mstv, array, GFT_INPUT_SPAR); */
}
/* Reset the touched array */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i) {
rpm -> chapar[i] = 1;
}
/* Count the number of parameters and put them in */
/* varele = fit -> varylist; */
/* i = 0; */
/* while (varele) { */
/* printf("varylist entry: %i\n",i); */
/* printf("elements:"); */
/* for (j = 0; j < varele -> nelem; ++j) { */
/* printf(" %i", varele -> elements[j]); */
/* } */
/* printf("\n "); */
/* for (j = 0; j < varele -> nelem; ++j) { */
/* printf(" %i", varele -> elements[j]%rpm -> nur); */
/* } */
/* printf("\n"); */
/* printf("\n"); */
/* ++i; */
/* varele = varele -> next; */
/* } */
/* Interpolate over the index once */
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
/* Deallocate things */
if ((array))
free(array);
if ((pointarray))
free(pointarray);
if (varylist && varylist != fit -> varylist)
destroyvarlel(varylist);
/* if ((varystr)) { */
/* free(varystr); */
/* } */
if ((varyhstr))
free(varyhstr);
if ((flistel))
destroyinlistel(flistel);
if ((decomp_controlv))
decomp_dest(decomp_controlv);
if ((decomp_listelv))
decomp_list_dest(decomp_listelv);
if (inputofvarysing)
freeparsed(inputofvarysing);
if (inputofvarymult)
freeparsed(inputofvarymult);
if (!(fit -> reg_contv = reg_cont_get(startinfv, hdr, rpm, fit)))
goto error;
return fit;
error:
destroy_fitparms(fit);
if ((adarv))
free(adarv);
if (varylist)
destroyvarlel(varylist);
if ((flistel))
destroyinlistel(flistel);
if ((varystr)) {
free(varystr);
}
if ((varyhstr))
free(varyhstr);
/* Allocate the pointarray */
if ((pointarray))
free(pointarray);
/* Allocate the */
if ((parmax))
free(parmax);
/* Allocate the */
if ((parmin))
free(parmin);
/* Allocate the */
if ((moderate))
free(moderate);
/* Allocate the */
if ((delstart))
free(delstart);
/* Allocate the */
if ((delend))
free(delend);
/* Allocate the */
if ((itestart))
free(itestart);
/* Allocate the */
if ((iteend))
free(iteend);
if ((satdelt))
free(satdelt);
if ((mindelta))
free(mindelta);
if ((array))
free(array);
if (inputofvarysing)
freeparsed(inputofvarysing);
if (inputofvarymult)
freeparsed(inputofvarymult);
if ((decomp_controlv))
decomp_dest(decomp_controlv);
if ((decomp_listelv))
decomp_list_dest(decomp_listelv);
/* if ((elements)) */
/* free(elements); */
/******/
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
static varlel *create_varylist_from_dcp(hdrinf *hdr, decomp_listel *decomp_listelv, double *parmax, double *parmin, int *moderate, double *delstart, double *delend, int *itestart, int *iteend, double *satdelt, double *mindelta, int nur, int ndisks)
{
varlel *varylist = NULL, *varyfirst = NULL;
int i = 0, j;
/******/
/******/
/* int obsint = 0; */
/* char obsmes[200]; */
/******/
if (!(decomp_listelv))
goto error;
if (!(varyfirst = appendvarlel(NULL)))
goto error;
varylist = varyfirst;
while (((decomp_listelv+i) -> nuel) != -1) {
varylist -> nelem = (decomp_listelv + i) -> nuel;
if (varylist -> nelem > 0) {
if (!((varylist -> elements) = (int *) malloc(varylist -> nelem * sizeof(int))))
goto error;
for (j = 0; j < varylist -> nelem; ++j)
varylist -> elements[j] = (decomp_listelv+i) -> poli[j];
/* poli[j] is the list of elements PXPOS etc., meaning that poli[0] points to the appropriate parameter */
varylist -> parmax = simpleglobtointern(parmax[(decomp_listelv + i) -> grnr], varylist -> nelem > 0?varylist -> elements[0]/nur+1:0, hdr, ndisks);
varylist -> parmin = simpleglobtointern(parmin[(decomp_listelv + i) -> grnr], varylist -> nelem > 0?varylist -> elements[0]/nur+1:0, hdr, ndisks);
varylist -> moderate = moderate[(decomp_listelv + i) -> grnr];
varylist -> delstart = ddparamtointern(delstart[(decomp_listelv + i) -> grnr], varylist -> nelem > 0?varylist -> elements[0]/nur+1:0, hdr, ndisks);
varylist -> delend = ddparamtointern(delend[(decomp_listelv + i) -> grnr], varylist -> nelem > 0?varylist -> elements[0]/nur+1:0, hdr, ndisks);
varylist -> itestart = itestart[(decomp_listelv + i) -> grnr];
varylist -> iteend = iteend[(decomp_listelv + i) -> grnr];
varylist -> satdelt = ddparamtointern(satdelt[(decomp_listelv + i) -> grnr], varylist -> nelem > 0?varylist -> elements[0]/nur+1:0, hdr, ndisks);
varylist -> mindelta = ddparamtointern(mindelta[(decomp_listelv + i) -> grnr], varylist -> nelem > 0?varylist -> elements[0]/nur+1:0, hdr, ndisks);
varylist -> indicator = 0;
varylist = appendvarlel(varylist);
}
++i;
}
varylist -> nelem = -1;
varylist -> elements = NULL;
/* The next stuff is a bit unfortunate, but we need a NULL-terminated list */
varylist = varyfirst;
if (varylist)
while (varylist -> nelem > -1 && varylist -> next -> nelem > -1)
varylist = varylist -> next;
if (varylist -> nelem > -1) {
free(varylist -> next);
varylist -> next = NULL;
}
else {
free(varylist);
return NULL;
}
return varyfirst;
error:
destroyvarlel(varyfirst);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
static int create_defaults_from_dcp(hdrinf *hdr, decomp_listel *decomp_listelv, double *parmax, double *parmin, int *moderate, double *delstart, double *delend, int *itestart, int *iteend, double *satdelt, double *mindelta, int nur, int ndisks, int fitmode)
{
int i = 0, parnum;
double value;
/******/
/******/
/* int obsint = 0; */
/* char obsmes[200]; */
/******/
if (!(decomp_listelv))
goto error;
while (((decomp_listelv+i) -> nuel) != -1) {
if ((decomp_listelv + i) -> nuel > 0) {
parnum = (decomp_listelv+i) -> poli[0];
/* poli[j] is the list of elements PXPOS etc., meaning that poli[0] points to the appropriate parameter */
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_PARMAX , &value)) return 1; parmax [(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_PARMIN , &value)) return 1; parmin [(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_MODERATE, &value)) return 1; moderate[(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_DELSTART, &value)) return 1; delstart[(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_DELEND , &value)) return 1; delend [(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_ITESTART, &value)) return 1; itestart[(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_ITEEND , &value)) return 1; iteend [(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_SATDELT , &value)) return 1; satdelt [(decomp_listelv + i) -> grnr] = value;
if (tirific_defaults_fitdefromident(parnum, nur, ndisks, fitmode, TIRIDENT_MINDELTA, &value)) return 1; mindelta[(decomp_listelv + i) -> grnr] = value;
}
++i;
}
return 0;
error:
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Conversion of some units */
static double simpleglobtointern(double value, int par, hdrinf *hdr, int ndisks)
{
int condisp;
condisp = (NPARAMS + (ndisks - 1)*NDPARAMS)+1;
if (par == RADI)
return value/hdr -> deltgridtouser[0];
if (par == (condisp))
return value/hdr -> deltgridtouser[2];
par = (par-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS + 1;
if (par == VROT)
return value/hdr -> deltgridtouser[2];
if (par == VRAD)
return value/hdr -> deltgridtouser[2];
if (par == VVER)
return value/hdr -> deltgridtouser[2];
if (par == DVRO)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (par == DVRA)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (par == DVVE)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (par == ZDRO)
return value/hdr -> deltgridtouser[0];
if (par == ZDRA)
return value/hdr -> deltgridtouser[0];
if (par == ZDVE)
return value/hdr -> deltgridtouser[0];
if (par == Z0)
/* Formerly) deltgridtouser[2]; */
return value/hdr -> deltgridtouser[0];
if (par == SBR)
return value/hdr -> jygridtouser;
if (par == SM1A)
return value/hdr -> jygridtouser;
if (par == SM1P)
return DEGTORAD*value;
if (par == SM2A)
return value/hdr -> jygridtouser;
if (par == SM2P)
return DEGTORAD*value;
if (par == SM3A)
return value/hdr -> jygridtouser;
if (par == SM3P)
return DEGTORAD*value;
if (par == SM4A)
return value/hdr -> jygridtouser;
if (par == SM4P)
return DEGTORAD*value;
if (par == GA1A)
return value/hdr -> jygridtouser;
if (par == GA1P)
return DEGTORAD*value;
if (par == GA1D)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (par == GA2A)
return value/hdr -> jygridtouser;
if (par == GA2P)
return DEGTORAD*value;
if (par == GA2D)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (par == GA3A)
return value/hdr -> jygridtouser;
if (par == GA3P)
return DEGTORAD*value;
if (par == GA3D)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (par == GA4A)
return value/hdr -> jygridtouser;
if (par == GA4P)
return DEGTORAD*value;
if (par == GA4D)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (par == AZ1P)
return DEGTORAD*value;
if (par == AZ1W)
return DEGTORAD*value;
if (par == AZ2P)
return DEGTORAD*value;
if (par == AZ2W)
return DEGTORAD*value;
if (par == INCL)
return DEGTORAD*value;
if (par == PA)
return DEGTORAD*(value+180);
/* globtointern */
if (par == XPOS)
return (value - hdr -> userglobcrval[0])/hdr -> userglobcdelt[0]+(hdr -> setcrpix[0]-1.0);
if (par == YPOS)
return (value - hdr -> userglobcrval[1])/hdr -> userglobcdelt[1]+(hdr -> setcrpix[1]-1.0);
if (par == VSYS)
return (value - hdr -> userglobcrval[2])/hdr -> userglobcdelt[2]+(hdr -> setcrpix[2]-1.0);
if (par == SDIS)
return value/hdr -> deltgridtouser[2];
if (par == CLNR)
return value;
if (par == VM0A)
return value/hdr -> deltgridtouser[2];
if (par == VM1A)
return value/hdr -> deltgridtouser[2];
if (par == VM1P)
return DEGTORAD*value;
if (par == VM2A)
return value/hdr -> deltgridtouser[2];
if (par == VM2P)
return DEGTORAD*value;
if (par == VM3A)
return value/hdr -> deltgridtouser[2];
if (par == VM3P)
return DEGTORAD*value;
if (par == VM4A)
return value/hdr -> deltgridtouser[2];
if (par == VM4P)
return DEGTORAD*value;
if (par == RA1A)
return value/hdr -> deltgridtouser[2];
if (par == RA1P)
return DEGTORAD*value;
if (par == RA2A)
return value/hdr -> deltgridtouser[2];
if (par == RA2P)
return DEGTORAD*value;
if (par == RA3A)
return value/hdr -> deltgridtouser[2];
if (par == RA3P)
return DEGTORAD*value;
if (par == RA4A)
return value/hdr -> deltgridtouser[2];
if (par == RA4P)
return DEGTORAD*value;
if (par == RO1A)
return value/hdr -> deltgridtouser[2];
if (par == RO1P)
return DEGTORAD*value;
if (par == RO2A)
return value/hdr -> deltgridtouser[2];
if (par == RO2P)
return DEGTORAD*value;
if (par == RO3A)
return value/hdr -> deltgridtouser[2];
if (par == RO3P)
return DEGTORAD*value;
if (par == RO4A)
return value/hdr -> deltgridtouser[2];
if (par == RO4P)
return DEGTORAD*value;
if (par == WM0A)
return value/hdr -> deltgridtouser[0];
if (par == WM1A)
return value/hdr -> deltgridtouser[0];
if (par == WM1P)
return DEGTORAD*value;
if (par == WM2A)
return value/hdr -> deltgridtouser[0];
if (par == WM2P)
return DEGTORAD*value;
if (par == WM3A)
return value/hdr -> deltgridtouser[0];
if (par == WM3P)
return DEGTORAD*value;
if (par == WM4A)
return value/hdr -> deltgridtouser[0];
if (par == WM4P)
return DEGTORAD*value;
if (par == LS0)
return value/hdr -> deltgridtouser[0];
if (par == LC0)
return value/hdr -> deltgridtouser[0];
return value;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Conversion of some units */
static double dparamtointern(double value, int par, hdrinf *hdr, int ndisks)
{
int condisp;
condisp = (NPARAMS + (ndisks - 1)*NDPARAMS)+1;
if (RADI == par)
return value/hdr -> deltgridtouser[0];
if (condisp == par)
return value/hdr -> deltgridtouser[2];
par = (par-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS+1;
if (VROT == par)
return value/hdr -> deltgridtouser[2];
if (VRAD == par)
return value/hdr -> deltgridtouser[2];
if (VVER == par)
return value/hdr -> deltgridtouser[2];
if (DVRO == par)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (DVRA == par)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (DVVE == par)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (ZDRO == par)
return value/hdr -> deltgridtouser[0];
if (ZDRA == par)
return value/hdr -> deltgridtouser[0];
if (ZDVE == par)
return value/hdr -> deltgridtouser[0];
if (Z0 == par)
return value/hdr -> deltgridtouser[0];
if (SBR == par)
return value/hdr -> jygridtouser;
if (SM1A == par)
return value/hdr -> jygridtouser;
if (SM1P == par)
return DEGTORAD*value;
if (SM2A == par)
return value/hdr -> jygridtouser;
if (SM2P == par)
return DEGTORAD*value;
if (SM3A == par)
return value/hdr -> jygridtouser;
if (SM3P == par)
return DEGTORAD*value;
if (SM4A == par)
return value/hdr -> jygridtouser;
if (SM4P == par)
return DEGTORAD*value;
if (GA1A == par)
return value/hdr -> jygridtouser;
if (GA1P == par)
return DEGTORAD*value;
if (GA1D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (GA2A == par)
return value/hdr -> jygridtouser;
if (GA2P == par)
return DEGTORAD*value;
if (GA2D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (GA3A == par)
return value/hdr -> jygridtouser;
if (GA3P == par)
return DEGTORAD*value;
if (GA3D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (GA4A == par)
return value/hdr -> jygridtouser;
if (GA4P == par)
return DEGTORAD*value;
if (GA4D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (AZ1P == par)
return DEGTORAD*value;
if (AZ1W == par)
return DEGTORAD*value;
if (AZ2P == par)
return DEGTORAD*value;
if (AZ2W == par)
return DEGTORAD*value;
if (INCL == par)
return DEGTORAD*value;
if (PA == par)
return DEGTORAD*(value+180);
if (XPOS == par)
return value/hdr -> globgridtouser[0];
if (YPOS == par)
return value/hdr -> globgridtouser[1];
if (VSYS == par)
return value/hdr -> globgridtouser[2];
if (SDIS == par)
return value/hdr -> deltgridtouser[2];
if (CLNR == par)
return value;
if (VM0A == par)
return value/hdr -> deltgridtouser[2];
/* These are the new ones */
if (VM1A == par)
return value/hdr -> deltgridtouser[2];
if (VM1P == par)
return DEGTORAD*value;
if (VM2A == par)
return value/hdr -> deltgridtouser[2];
if (VM2P == par)
return DEGTORAD*value;
if (VM3A == par)
return value/hdr -> deltgridtouser[2];
if (VM3P == par)
return DEGTORAD*value;
if (VM4A == par)
return value/hdr -> deltgridtouser[2];
if (VM4P == par)
return DEGTORAD*value;
if (RA1A == par)
return value/hdr -> deltgridtouser[2];
if (RA1P == par)
return DEGTORAD*value;
if (RA2A == par)
return value/hdr -> deltgridtouser[2];
if (RA2P == par)
return DEGTORAD*value;
if (RA3A == par)
return value/hdr -> deltgridtouser[2];
if (RA3P == par)
return DEGTORAD*value;
if (RA4A == par)
return value/hdr -> deltgridtouser[2];
if (RA4P == par)
return DEGTORAD*value;
if (RO1A == par)
return value/hdr -> deltgridtouser[2];
if (RO1P == par)
return DEGTORAD*value;
if (RO2A == par)
return value/hdr -> deltgridtouser[2];
if (RO2P == par)
return DEGTORAD*value;
if (RO3A == par)
return value/hdr -> deltgridtouser[2];
if (RO3P == par)
return DEGTORAD*value;
if (RO4A == par)
return value/hdr -> deltgridtouser[2];
if (RO4P == par)
return DEGTORAD*value;
if (WM0A == par)
return value/hdr -> deltgridtouser[0];
if (WM1A == par)
return value/hdr -> deltgridtouser[0];
if (WM1P == par)
return DEGTORAD*value;
if (WM2A == par)
return value/hdr -> deltgridtouser[0];
if (WM2P == par)
return DEGTORAD*value;
if (WM3A == par)
return value/hdr -> deltgridtouser[0];
if (WM3P == par)
return DEGTORAD*value;
if (WM4A == par)
return value/hdr -> deltgridtouser[0];
if (WM4P == par)
return DEGTORAD*value;
if (LC0 == par)
return value/hdr -> deltgridtouser[0];
if (LS0 == par)
return value/hdr -> deltgridtouser[0];
return value;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Conversion of some units */
static double ddparamtointern(double value, int par, hdrinf *hdr, int ndisks)
{
int condisp;
condisp = (NPARAMS + (ndisks - 1)*NDPARAMS)+1;
if (RADI == par)
return value/hdr -> deltgridtouser[0];
if ((condisp) == par)
return value/hdr -> deltgridtouser[2];
par = (par-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS+1;
if (VROT == par)
return value/hdr -> deltgridtouser[2];
if (VRAD == par)
return value/hdr -> deltgridtouser[2];
if (VVER == par)
return value/hdr -> deltgridtouser[2];
if (DVRO == par)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (DVRA == par)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (DVVE == par)
return value/hdr -> deltgridtouser[2]*hdr -> deltgridtouser[0];
if (Z0 == par)
return value/hdr -> deltgridtouser[0];
if (ZDRO == par)
return value/hdr -> deltgridtouser[0];
if (ZDRA == par)
return value/hdr -> deltgridtouser[0];
if (ZDVE == par)
return value/hdr -> deltgridtouser[0];
if (SBR == par)
return value/hdr -> jygridtouser;
if (SM1A == par)
return value/hdr -> jygridtouser;
if (SM1P == par)
return DEGTORAD*value;
if (SM2A == par)
return value/hdr -> jygridtouser;
if (SM2P == par)
return DEGTORAD*value;
if (SM3A == par)
return value/hdr -> jygridtouser;
if (SM3P == par)
return DEGTORAD*value;
if (SM4A == par)
return value/hdr -> jygridtouser;
if (SM4P == par)
return DEGTORAD*value;
if (GA1A == par)
return value/hdr -> jygridtouser;
if (GA1P == par)
return DEGTORAD*value;
if (GA1D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (GA2A == par)
return value/hdr -> jygridtouser;
if (GA2P == par)
return DEGTORAD*value;
if (GA2D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (GA3A == par)
return value/hdr -> jygridtouser;
if (GA3P == par)
return DEGTORAD*value;
if (GA3D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (GA4A == par)
return value/hdr -> jygridtouser;
if (GA4P == par)
return DEGTORAD*value;
if (GA4D == par)
return value/hdr -> deltgridtouser[0];
/* return DEGTORAD*value; */
if (AZ1P == par)
return DEGTORAD*value;
if (AZ1W == par)
return DEGTORAD*value;
if (AZ2P == par)
return DEGTORAD*value;
if (AZ2W == par)
return DEGTORAD*value;
if (INCL == par)
return DEGTORAD*value;
if (PA == par)
return DEGTORAD*(value);
if (XPOS == par)
return value/hdr -> globgridtouser[0];
if (YPOS == par)
return value/hdr -> globgridtouser[1];
if (VSYS == par)
return value/hdr -> globgridtouser[2];
if (SDIS == par)
return value/hdr -> deltgridtouser[2];
if (CLNR == par)
return value;
if (VM0A == par)
return value/hdr -> deltgridtouser[2];
/* These are the new ones */
if (VM1A == par)
return value/hdr -> deltgridtouser[2];
if (VM1P == par)
return DEGTORAD*value;
if (VM2A == par)
return value/hdr -> deltgridtouser[2];
if (VM2P == par)
return DEGTORAD*value;
if (VM3A == par)
return value/hdr -> deltgridtouser[2];
if (VM3P == par)
return DEGTORAD*value;
if (VM4A == par)
return value/hdr -> deltgridtouser[2];
if (VM4P == par)
return DEGTORAD*value;
if (RA1A == par)
return value/hdr -> deltgridtouser[2];
if (RA1P == par)
return DEGTORAD*value;
if (RA2A == par)
return value/hdr -> deltgridtouser[2];
if (RA2P == par)
return DEGTORAD*value;
if (RA3A == par)
return value/hdr -> deltgridtouser[2];
if (RA3P == par)
return DEGTORAD*value;
if (RA4A == par)
return value/hdr -> deltgridtouser[2];
if (RA4P == par)
return DEGTORAD*value;
if (RO1A == par)
return value/hdr -> deltgridtouser[2];
if (RO1P == par)
return DEGTORAD*value;
if (RO2A == par)
return value/hdr -> deltgridtouser[2];
if (RO2P == par)
return DEGTORAD*value;
if (RO3A == par)
return value/hdr -> deltgridtouser[2];
if (RO3P == par)
return DEGTORAD*value;
if (RO4A == par)
return value/hdr -> deltgridtouser[2];
if (RO4P == par)
return DEGTORAD*value;
if (WM0A == par)
return value/hdr -> deltgridtouser[0];
if (WM1A == par)
return value/hdr -> deltgridtouser[0];
if (WM1P == par)
return DEGTORAD*value;
if (WM2A == par)
return value/hdr -> deltgridtouser[0];
if (WM2P == par)
return DEGTORAD*value;
if (WM3A == par)
return value/hdr -> deltgridtouser[0];
if (WM3P == par)
return DEGTORAD*value;
if (WM4A == par)
return value/hdr -> deltgridtouser[0];
if (WM4P == par)
return DEGTORAD*value;
if (LC0 == par)
return value/hdr -> deltgridtouser[0];
if (LS0 == par)
return value/hdr -> deltgridtouser[0];
return value;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Conversion of some units */
static double dinterntoparam(double value, int par, hdrinf *hdr, int ndisks)
{
int condisp;
condisp = (NPARAMS + (ndisks - 1)*NDPARAMS)+1;
if (RADI == par)
return value*hdr -> deltgridtouser[0];
if ((condisp) == par)
return value*hdr -> deltgridtouser[2];
par = (par-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS + 1;
if (VROT == par)
return value*hdr -> deltgridtouser[2];
if (VRAD == par)
return value*hdr -> deltgridtouser[2];
if (VVER == par)
return value*hdr -> deltgridtouser[2];
if (DVRO == par)
return value*hdr -> deltgridtouser[2]/hdr -> deltgridtouser[0];
if (DVRA == par)
return value*hdr -> deltgridtouser[2]/hdr -> deltgridtouser[0];
if (DVVE == par)
return value*hdr -> deltgridtouser[2]/hdr -> deltgridtouser[0];
if (Z0 == par)
return value*hdr -> deltgridtouser[1];
if (ZDRO == par)
return value*hdr -> deltgridtouser[1];
if (ZDRA == par)
return value*hdr -> deltgridtouser[1];
if (ZDVE == par)
return value*hdr -> deltgridtouser[1];
if (SBR == par)
return value*hdr -> jygridtouser;
if (SM1A == par)
return value*hdr -> jygridtouser;
if (SM1P == par)
return RADTODEG*value;
if (SM2A == par)
return value*hdr -> jygridtouser;
if (SM2P == par)
return RADTODEG*value;
if (SM3A == par)
return value*hdr -> jygridtouser;
if (SM3P == par)
return RADTODEG*value;
if (SM4A == par)
return value*hdr -> jygridtouser;
if (SM4P == par)
return RADTODEG*value;
if (GA1A == par)
return value*hdr -> jygridtouser;
if (GA1P == par)
return RADTODEG*value;
if (GA1D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (GA2A == par)
return value*hdr -> jygridtouser;
if (GA2P == par)
return RADTODEG*value;
if (GA2D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (GA3A == par)
return value*hdr -> jygridtouser;
if (GA3P == par)
return RADTODEG*value;
if (GA3D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (GA4A == par)
return value*hdr -> jygridtouser;
if (GA4P == par)
return RADTODEG*value;
if (GA4D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (AZ1P == par)
return RADTODEG*value;
if (AZ1W == par)
return RADTODEG*value;
if (AZ2P == par)
return RADTODEG*value;
if (AZ2W == par)
return RADTODEG*value;
if (INCL == par)
return RADTODEG*value;
if (PA == par)
return RADTODEG*value-180;
if (XPOS == par)
return value*hdr -> globgridtouser[0];
if (YPOS == par)
return value*hdr -> globgridtouser[1];
if (VSYS == par)
return value*hdr -> globgridtouser[2];
if (condisp == par)
return value*hdr -> deltgridtouser[2];
if (SDIS == par)
return value*hdr -> deltgridtouser[2];
if (CLNR == par)
return value;
/* These are the new ones */
if (VM1A == par)
return value*hdr -> deltgridtouser[2];
if (VM1P == par)
return RADTODEG*value;
if (VM2A == par)
return value*hdr -> deltgridtouser[2];
if (VM2P == par)
return RADTODEG*value;
if (VM3A == par)
return value*hdr -> deltgridtouser[2];
if (VM3P == par)
return RADTODEG*value;
if (VM4A == par)
return value*hdr -> deltgridtouser[2];
if (VM4P == par)
return RADTODEG*value;
if (RA1A == par)
return value*hdr -> deltgridtouser[2];
if (RA1P == par)
return RADTODEG*value;
if (RA2A == par)
return value*hdr -> deltgridtouser[2];
if (RA2P == par)
return RADTODEG*value;
if (RA3A == par)
return value*hdr -> deltgridtouser[2];
if (RA3P == par)
return RADTODEG*value;
if (RA4A == par)
return value*hdr -> deltgridtouser[2];
if (RA4P == par)
return RADTODEG*value;
if (RO1A == par)
return value*hdr -> deltgridtouser[2];
if (RO1P == par)
return RADTODEG*value;
if (RO2A == par)
return value*hdr -> deltgridtouser[2];
if (RO2P == par)
return RADTODEG*value;
if (RO3A == par)
return value*hdr -> deltgridtouser[2];
if (RO3P == par)
return RADTODEG*value;
if (RO4A == par)
return value*hdr -> deltgridtouser[2];
if (RO4P == par)
return RADTODEG*value;
if (VM0A == par)
return value*hdr -> deltgridtouser[2];
if (WM0A == par)
return value*hdr -> deltgridtouser[0];
if (WM1A == par)
return value*hdr -> deltgridtouser[0];
if (WM1P == par)
return RADTODEG*value;
if (WM2A == par)
return value*hdr -> deltgridtouser[0];
if (WM2P == par)
return RADTODEG*value;
if (WM3A == par)
return value*hdr -> deltgridtouser[0];
if (WM3P == par)
return RADTODEG*value;
if (WM4A == par)
return value*hdr -> deltgridtouser[0];
if (WM4P == par)
return RADTODEG*value;
if (LC0 == par)
return value*hdr -> deltgridtouser[0];
if (LS0 == par)
return value*hdr -> deltgridtouser[0];
return value;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Conversion of some units */
static double ddinterntoparam(double value, int par, hdrinf *hdr, int ndisks)
{
int condisp;
condisp = (NPARAMS + (ndisks - 1)*NDPARAMS)+1;
if (RADI == par)
return value*hdr -> deltgridtouser[0];
if ((condisp) == par)
return value*hdr -> deltgridtouser[2];
par = (par-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS + 1;
if (VROT == par)
return value*hdr -> deltgridtouser[2];
if (VRAD == par)
return value*hdr -> deltgridtouser[2];
if (VVER == par)
return value*hdr -> deltgridtouser[2];
if (DVRO == par)
return value*hdr -> deltgridtouser[2]/hdr -> deltgridtouser[0];
if (DVRA == par)
return value*hdr -> deltgridtouser[2]/hdr -> deltgridtouser[0];
if (DVVE == par)
return value*hdr -> deltgridtouser[2]/hdr -> deltgridtouser[0];
if (ZDRO == par)
return value*hdr -> deltgridtouser[1];
if (ZDRA == par)
return value*hdr -> deltgridtouser[1];
if (ZDVE == par)
return value*hdr -> deltgridtouser[1];
if (Z0 == par)
return value*hdr -> deltgridtouser[1];
if (SBR == par)
return value*hdr -> jygridtouser;
if (SM1A == par)
return value*hdr -> jygridtouser;
if (SM1P == par)
return RADTODEG*value;
if (SM2A == par)
return value*hdr -> jygridtouser;
if (SM2P == par)
return RADTODEG*value;
if (SM3A == par)
return value*hdr -> jygridtouser;
if (SM3P == par)
return RADTODEG*value;
if (SM4A == par)
return value*hdr -> jygridtouser;
if (SM4P == par)
return RADTODEG*value;
if (GA1A == par)
return value*hdr -> jygridtouser;
if (GA1P == par)
return RADTODEG*value;
if (GA1D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (GA2A == par)
return value*hdr -> jygridtouser;
if (GA2P == par)
return RADTODEG*value;
if (GA2D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (GA3A == par)
return value*hdr -> jygridtouser;
if (GA3P == par)
return RADTODEG*value;
if (GA3D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (GA4A == par)
return value*hdr -> jygridtouser;
if (GA4P == par)
return RADTODEG*value;
if (GA4D == par)
return value*hdr -> deltgridtouser[0];
/* return RADTODEG*value; */
if (AZ1P == par)
return RADTODEG*value;
if (AZ1W == par)
return RADTODEG*value;
if (AZ2P == par)
return RADTODEG*value;
if (AZ2W == par)
return RADTODEG*value;
if (INCL == par)
return RADTODEG*value;
if (PA == par)
return RADTODEG*value;
if (XPOS == par)
return value*hdr -> globgridtouser[0];
if (YPOS == par)
return value*hdr -> globgridtouser[1];
if (VSYS == par)
return value*hdr -> globgridtouser[2];
if (condisp == par)
return value*hdr -> deltgridtouser[2];
if (SDIS == par)
return value*hdr -> deltgridtouser[2];
if (CLNR == par)
return value;
if (VM1A == par)
return value*hdr -> deltgridtouser[2];
if (VM1P == par)
return RADTODEG*value;
/* These are the new ones */
if (VM1A == par)
return value*hdr -> deltgridtouser[2];
if (VM1P == par)
return RADTODEG*value;
if (VM2A == par)
return value*hdr -> deltgridtouser[2];
if (VM2P == par)
return RADTODEG*value;
if (VM3A == par)
return value*hdr -> deltgridtouser[2];
if (VM3P == par)
return RADTODEG*value;
if (VM4A == par)
return value*hdr -> deltgridtouser[2];
if (VM4P == par)
return RADTODEG*value;
if (RA1A == par)
return value*hdr -> deltgridtouser[2];
if (RA1P == par)
return RADTODEG*value;
if (RA2A == par)
return value*hdr -> deltgridtouser[2];
if (RA2P == par)
return RADTODEG*value;
if (RA3A == par)
return value*hdr -> deltgridtouser[2];
if (RA3P == par)
return RADTODEG*value;
if (RA4A == par)
return value*hdr -> deltgridtouser[2];
if (RA4P == par)
return RADTODEG*value;
if (RO1A == par)
return value*hdr -> deltgridtouser[2];
if (RO1P == par)
return RADTODEG*value;
if (RO2A == par)
return value*hdr -> deltgridtouser[2];
if (RO2P == par)
return RADTODEG*value;
if (RO3A == par)
return value*hdr -> deltgridtouser[2];
if (RO3P == par)
return RADTODEG*value;
if (RO4A == par)
return value*hdr -> deltgridtouser[2];
if (RO4P == par)
return RADTODEG*value;
if (VM0A == par)
return value*hdr -> deltgridtouser[2];
if (WM0A == par)
return value*hdr -> deltgridtouser[0];
if (WM1A == par)
return value*hdr -> deltgridtouser[0];
if (WM1P == par)
return RADTODEG*value;
if (WM2A == par)
return value*hdr -> deltgridtouser[0];
if (WM2P == par)
return RADTODEG*value;
if (WM3A == par)
return value*hdr -> deltgridtouser[0];
if (WM3P == par)
return RADTODEG*value;
if (WM4A == par)
return value*hdr -> deltgridtouser[0];
if (WM4P == par)
return RADTODEG*value;
if (LC0 == par)
return value*hdr -> deltgridtouser[0];
if (LS0 == par)
return value*hdr -> deltgridtouser[0];
return value;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* conversion of map units */
static void globtointern(double *invalue, double *outvalue, hdrinf *hdr)
{
/* int transformation = 0; */
double world[3];
/* double proutvalue[3]; */
/* int vint; */
/* For the sake of velocity, we know the following transformations, if we'd know that we would not require invalue, we could be even faster */
world[0] = invalue[0]; /* deg */
world[1] = invalue[1]; /* deg */
world[2] = invalue[2]*1000.; /* m/s from km/s, I hope */
/*The function converts directly from w to absolute pixels */
cubarithm_w2p(hdr -> oric -> wcs, world, outvalue);
/* cubarithm_w2p(hdr -> oric -> wcs, world, proutvalue); */
/* outvalue[0] = proutvalue[0]+hdr -> setcrpix[0]-1; */
/* outvalue[1] = proutvalue[1]+hdr -> setcrpix[1]-1; */
/* outvalue[2] = proutvalue[2]+hdr -> setcrpix[2]-1; */
/* below that line, it's very old stuff */
/*********************/
/* Transform the map units into grids */
/* dbldbl[0] = invalue[0]/hdr -> globsettouser[0]; */
/* dbldbl[1] = invalue[1]/hdr -> globsettouser[1]; */
/* Get the map unit belonging to velocity */
/* outvalue[2] = (invalue[2] - hdr -> userglobcrval[2])/hdr -> userglobcdelt[2]+(hdr -> setcrpix[2]-1.0); */
/* We assign this to a grid position */
/* vint = roundnormal(outvalue[2]); */
/* There are maximal and minimal values that can be set */
/* if (vint < 0) */
/* vint = 0; */
/* if (vint >= hdr -> nsubs) */
/* vint = hdr -> nsubs-1; */
/* Now do the transformation, it should work */
/* cotrans_tir(hdr -> inset, &hdr -> insubs[vint], dbldbl, outvalue, &transformation); */
/* Now we have grids that we have to transform to maps */
/* outvalue[0] = outvalue[0]+hdr -> setcrpix[0]-1; */
/* outvalue[1] = outvalue[1]+hdr -> setcrpix[1]-1; */
/* Again, the map unit belonging to velocity, because cotrans does a nasty thing */
/* outvalue[2] = (invalue[2] - hdr -> userglobcrval[2])/hdr -> userglobcdelt[2]+(hdr -> setcrpix[2]-1.0); */
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* conversion of map units */
static void interntoglob(double *invalue, double *outvalue, hdrinf *hdr)
{
/* int transformation = 1; */
/* double dbldbl[2]; */
/* int vint; */
/* double relpix[3]; */
double abspix[3];
/* Transform the map units into grid units, this is absolute pixel values, starting at 0 */
abspix[0] = invalue[0];
abspix[1] = invalue[1];
abspix[2] = invalue[2];
/* This would be relative values, as formerly required by gipsy */
/* relpix[0] = invalue[0]-hdr -> setcrpix[0]+1; */
/* relpix[1] = invalue[1]-hdr -> setcrpix[1]+1; */
/* relpix[2] = invalue[2]-hdr -> setcrpix[2]+1; */
/* cubarithm_p2w(hdr -> oric -> wcs, relpix, outvalue); */
cubarithm_p2w(hdr -> oric -> wcs, abspix, outvalue);
/* This is to take into account that the global units are always degrees (as in tirific) and m/s (which is 1/1000 the tirific unit) */
outvalue[2] = outvalue[2]*0.001;
/* We assign the velocity to a map position */
/* vint = roundnormal(invalue[2]); */
/* There are maximal and minimal values that can be set */
/* if (vint < 0) */
/* vint = 0; */
/* if (vint >= hdr -> nsubs) */
/* vint = hdr -> nsubs-1; */
/* Now do the transformation, it should work */
/* cotrans_tir(hdr -> inset, &hdr -> insubs[vint], dbldbl, outvalue, &transformation); */
/* Get the user unit belonging to velocity */
/* outvalue[0] = outvalue[0]*hdr -> globsettouser[0]; */
/* outvalue[1] = outvalue[1]*hdr -> globsettouser[1]; */
/* outvalue[2] = (invalue[2]-hdr -> setcrpix[2]+1)*hdr -> userglobcdelt[2]+hdr -> userglobcrval[2]; */
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Change the parameter list params to internal units as if being user units */
static void changetointern(double *params, int nur, hdrinf *hdr, int ndisks)
{
/* OK */
int i,j,k,disk;
double globin[3];
double globout[3];
int condisp, pcondisp;
/* for (i = 0; i < nur; ++i) { */
/* Some of the easily convertable thingies */
/* params[PRADI*nur+i] = dparamtointern(params[PRADI*nur+i], RADI, hdr); */
/* } */
/* This is all very simple */
for (disk = 0; disk < ndisks; ++disk){
j = PRPARAMS+disk*NDPARAMS;
for (i = 0; i < nur; ++i) {
for (k = 0; k < NDPARAMS; ++k) {
if ((k != PXPOS) && (k != PYPOS) &&(k != PVSYS))
params[(j+k)*nur+i] = dparamtointern(params[(j+k)*nur+i], j+k+1, hdr, ndisks);
}
/* Now, we have to convert the triplets into internal units */
globin[0] = params[(j+PXPOS)*nur+i];
globin[1] = params[(j+PYPOS)*nur+i];
globin[2] = params[(j+PVSYS)*nur+i];
globtointern(globin, globout, hdr);
params[(j+PXPOS)*nur+i] = globout[0];
params[(j+PYPOS)*nur+i] = globout[1];
params[(j+PVSYS)*nur+i] = globout[2];
}
}
pcondisp = (NPARAMS + (ndisks - 1)*NDPARAMS);
condisp = pcondisp + 1;
params[pcondisp*nur] = dparamtointern(params[pcondisp*nur], condisp, hdr, ndisks);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Constructor of an element of the varlel list */
static varlel *appendvarlel(varlel *last)
{
varlel *out;
if (!(out = (varlel *) malloc(sizeof(varlel))))
return NULL;
if ((last))
last -> next = out;
/* "Terminate" */
out -> elements = NULL;
out -> nelem = 0;
out -> next = NULL;
return out;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Destructor of a varlel list */
static void destroyvarlel(varlel *first)
{
varlel *next;
while ((first)) {
/* Convention is that elements is dynamically allocated */
if ((first -> nelem) > 0)
free(first -> elements);
next = first -> next;
free(first);
first = next;
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* write the output cube */
static int writemodel(hdrinf *origin, ringparms *rpm, fitparms *fit, double *par, decomp_inlist *index)
{
int i=0;
/* char mes[200]; */
int pcondisp;
/* int checki = 0, checkia = 0; */
/* int allnpoints[ndisks]; */
pcondisp = (NPARAMS + (rpm -> ndisks - 1)*NDPARAMS);
/* If outset is not defined, we stop here */
if (*origin -> outset == '\0') {
return 1;
}
/* We have to put the current best values to the cube */
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i) {
rpm -> par[i] = par[i];
}
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
/* Testing */
/* for(k = 0; k < origin -> nsubs; ++k) */
/* for(j = 0; j < origin -> bsize2; ++j) */
/* for(i = 0; i < origin -> bsize1; ++i) */
/* if (origin -> modelc -> points[i+2*(origin -> bsize1/2+1)*(j+origin -> bsize2*k)] > 0.) */
/* checkia = 1; */
/* if (checkia == 1) */
/* printf("Is not empty\n"); */
/* else { */
/* printf("Is empty\n"); */
/* } */
/* Then we generate the cube and convolve it */
galmod(origin, rpm, 1, NULL, index, rpm -> fluxpoints, rpm -> allnpoints);
origin -> chi2 = getchisquare_c(rpm -> par[(pcondisp)*rpm -> nur]);
/* Regularise */
origin -> chi2 = reg_do(fit -> reg_contv, (fit -> mon_alloops == fit -> loops)?fit -> loops - 1:fit -> mon_alloops, origin -> chi2);
/* Correct the chisquare taking into account the outliers, don't know if that is necessary here... */
origin -> chi2 = origin -> chi2+((double) rpm -> outpoints)*rpm -> penalty;
/* Now rearrange the cube */
/* for(k = 0; k < origin -> nsubs; ++k) */
/* for(j = 0; j < origin -> bsize2; ++j) */
/* for(i = 0; i < origin -> bsize1; ++i) */
/* origin -> model[i+origin -> bsize1*(j+origin -> bsize2*k)] = origin -> model[i+2*(origin -> bsize1/2+1)*(j+origin -> bsize2*k)]; */
/* origin -> primbeam[i+origin -> bsize1*(j)]; */
/* Write the cube plane by plane, really too lazy to track min and max */
/* change this first */
/* origin -> nprof = origin -> bsize1*origin -> bsize2; */
/* for (i = 0; i < origin -> nsubs; ++i) { */
/* j=i*origin -> nprof; */
/* My god, this has to be set, otherways: crash... */
/* l = 0; */
/* gdsi_write_tir(origin -> outset, origin -> cwlo+i, origin -> cwhi+i, origin -> model+j, &origin -> nprof, &k, &l); */
/* if (l) { */
/* i = 1; */
/* sprintf(mes, "Unable to write outset with error %i.", l); */
/* error_tir(&i, mes); */
/* return 0; */
/* } */
/* } */
/* This should do */
cubarithm_writecube(origin -> modelc, origin -> outset, NULL);
/* Now change this back */
/* origin -> nprof = origin -> bcsize1*origin -> bsize2; */
return 1;
error:
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* write the output cube */
static int writecoolmodel(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, double *par, decomp_inlist *index)
{
int i=0;
char *coolname = NULL;
char **varystr = NULL;
int keypres, nread, nreturned;
char mes[81];
int def;
int nel;
int err;
/* These should be replaced with the default cube stuff */
qfits_header *header;
Cube *thecube = NULL;
double beam;
float *expfcs;
float sincosofangle[2];
long fluxpoints;
int allnpoints;
/* pcondisp = (NPARAMS + (rpm -> ndisks - 1)*NDPARAMS); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "COOLGAL", "Give cool name.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(coolname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(coolname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* The default is to do nothing */
if (*coolname == '\0') {
free(coolname);
return 1;
}
/* Now we want the binning number */
sprintf(mes, "Give cool binning");
def = 2;
nel = 1;
err = 1;
hdr -> coolbin = 1;
while((err)) {
userint_tir(startinfv -> arel, &(hdr -> coolbin), &nel, &def, "COOLBIN=", mes);
if (hdr -> coolbin >= 1) {
err = 0;
}
else {
sprintf(mes, "COOLBIN should be >= 1");
cancel_tir(startinfv -> arel, "COOLBIN=", 2);
hdr -> coolbin = 1;
def = 1;
}
}
/* Now ask if the user wants a specific kind of beam, the default being the max beam */
sprintf(mes, "Give 3d beam size (arcsec)");
beam = hdr -> deltgridtouser[0]*((double) hdr -> bmaj);
def = 2;
nel = 1;
err = 1;
beam = 10;
while((err)) {
userdble_tir(startinfv -> arel, &beam, &nel, &def, "COOLBEAM=", mes);
if (beam >= 0.0) {
err = 0;
}
else {
sprintf(mes, "COOLBEAM should be >= 0");
cancel_tir(startinfv -> arel, "COOLBEAM=", 2);
beam = hdr -> deltgridtouser[0]*((double) hdr -> bmaj);
def = 1;
}
}
/* Transfer the beam into deg */
beam = hdr -> globgridtouser[0]*beam/hdr -> deltgridtouser[0];
/* Make a header, if the beam is 0, we normalise everything such that the units get right */
if (!(header = makecoolhdr(hdr, ((beam))?beam:sqrt(TWOPI)/(hdr -> globgridtouser[0]*0.42466090014401))))
return 1;
/* Transfer the beam back to grid units */
beam = beam*hdr -> coolbin/(hdr -> globgridtouser[0]);
/* Now arrange the cube */
if (!(thecube = (Cube *) malloc(sizeof(Cube))))
goto error;
thecube -> refpix_x = 0;
thecube -> refpix_y = 0;
thecube -> refpix_v = 0;
thecube -> size_x = hdr -> bsize1*hdr -> coolbin;
thecube -> size_y = hdr -> bsize2*hdr -> coolbin;
thecube -> size_v = (thecube -> size_x > thecube -> size_y)?thecube -> size_x:thecube -> size_y;
thecube -> scale = 1.0;
thecube -> padding = 0;
/* As a precaution, these are not required, but must be set to NULL to avoid a free on some non-alloced stuff */
thecube -> type_x = NULL;
thecube -> type_y = NULL;
thecube -> type_v = NULL;
thecube -> epoch = NULL;
thecube -> type = NULL;
thecube -> unit = NULL;
thecube -> asciiheader = NULL;
thecube -> points = NULL;
thecube -> wcs = NULL;
/* This is required for gridding */
hdr -> coolhalfc = ((float) thecube -> size_v)/2;
hdr -> nprofcool = thecube -> size_x*thecube -> size_y;
tir_get_grid(log, rpm, log -> outarray);
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i)
rpm -> par[i] = log -> outarray[i];
/* Convert the read parameter list to internal units */
changetointern(rpm -> par, rpm -> nur, hdr, rpm -> ndisks);
/* provide some info */
nel=1;
sprintf(mes, "Cool number of bytes used: %lu", thecube -> size_x*thecube -> size_y*thecube -> size_v*sizeof(float));
anyout_tir(&nel, mes);
/* Now we allocate the cube, not caring for the padding, this will be done automatically */
if (!(thecube -> points = (float *) fftwf_malloc(thecube -> size_x*thecube -> size_y*thecube -> size_v*sizeof(float)))) {
ftsout_header_destroy(header);
return 1;
}
hdr -> coolcube = thecube;
/* We have to put the current best values to the cube */
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i) {
rpm -> par[i] = par[i];
}
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
/* correct dependent parameters */
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
/* Then we generate the cube and convolve it */
galmodcool(hdr, rpm, 1, NULL, index, &fluxpoints, &allnpoints);
/* Convolve it */
sincosofangle[0] = 0;
sincosofangle[1] = 1;
if (!(expfcs = expofacsfft(0.42466090014401*beam, 0.42466090014401*beam, 0.42466090014401*beam, sincosofangle))) {
ftsout_header_destroy(header);
return 1;
}
/* Now, the normalisation is the fifth factor, we multiply it with this */
expfcs[4] = expfcs[4]*sqrtf(TWOPI)*0.42466090014401*beam;
/* This is the actual convolution */
if ((beam)) {
convolgaussfft(thecube, expfcs);
}
/* Output it */
ftsout_writecube(coolname, thecube, header);
/* Deallocate everything */
ftsout_header_destroy(header);
free(thecube -> points);
thecube -> points = NULL;
free(expfcs);
/* Finally */
if ((coolname))
free(coolname);
if ((varystr))
freeparsed(varystr);
return 1;
error:
/* Strangely, for this function, 0 returned means error. This is an old functino... */
if ((thecube)) {
if (hdr -> coolcube)
cubarithm_cube_destroy(hdr -> coolcube);
else
cubarithm_cube_destroy(thecube);
}
if ((coolname))
free(coolname);
if ((varystr))
freeparsed(varystr);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Destructor of a inlistel list */
static void destroyinlistel(inlistel *first)
{
inlistel *next;
while ((first)) {
/* Convention is that elements is dynamically allocated */
next = first -> next;
free(first);
first = next;
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Opens a file and puts an old-style ascii header to the top */
static void prepout(loginf *log, hdrinf *hdr, ringparms *rpm)
{
int i, j;
char key[21];
/* Start with the usual check */
if (*log -> textlog == '\0')
return;
/* We try to open write append without header if the file exists,
without checking the content, first closing if this exists */
if ((log -> tstream)) {
fclose(log -> tstream);
log -> tstream = NULL;
}
if (!(log -> tstream = fopen(log -> textlog, "r"))) {
/* If the file doesn't exist we compose a header */
if ((log -> tstream = fopen(log -> textlog, "w"))) {
/* Turn off the buffering for tstream */
setbuf(log -> tstream, NULL);
fprintf(log -> tstream, " MODEL# ");
/* We now compose a header entry for each keyword including radius */
for (i = 1; i <= (NPARAMS+(rpm -> ndisks-1)*NDPARAMS); ++i) {
for (j = 0; j < rpm -> nur; ++j) {
/* Put the title */
ftstab_putcoltitl(key, i);
fprintf(log -> tstream, "%6s", key);
/* Now with an underscore the radius */
fprintf(log -> tstream, "_%04.1f ", dinterntoparam(rpm -> par[PRADI+j], RADI, hdr, rpm -> ndisks));
}
}
for (i = 1; i <= NSPARAMS; ++i) {
ftstab_putcoltitl(key, i+(NPARAMS+(rpm -> ndisks-1)*NDPARAMS));
fprintf(log -> tstream, "%11s", key);
}
/* The chisquare, the reduced chisquare and acceptance */
ftstab_putcoltitl(key, NPARAMS+(rpm -> ndisks-1)*NDPARAMS+NSPARAMS+(LASTSING_PRIMPOS+NUMB_MDPRIMPOS*rpm -> ndisks)+SECHDN_MULTI+CHISQ_TABNR);
fprintf(log -> tstream, "%23s", key);
ftstab_putcoltitl(key, NPARAMS+(rpm -> ndisks-1)*NDPARAMS+NSPARAMS+(LASTSING_PRIMPOS+NUMB_MDPRIMPOS*rpm -> ndisks)+SECHDN_MULTI+RCHISQ_TABNR);
fprintf(log -> tstream, "%23s", key);
ftstab_putcoltitl(key, NPARAMS+(rpm -> ndisks-1)*NDPARAMS+NSPARAMS+(LASTSING_PRIMPOS+NUMB_MDPRIMPOS*rpm -> ndisks)+SECHDN_MULTI+ACCEPT_TABNR);
fprintf(log -> tstream, "%10s", key);
fprintf(log -> tstream,"\n");
}
}
else {
log -> tstream = fopen(log -> textlog, "a");
/* Turn off the buffering for tstream */
setbuf(log -> tstream, NULL);
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generic fitting using the gft */
static int genfit(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
double indpoints; /* Independent data points */
double *dblarray = NULL;
double change;
double dpar;
size_t npar;
size_t asize_t = 1, hereiter;
int maxmod, anintege; /* maximum occurrence of moderate */
int i,j,k;
varlel *nextvarlel;
/* This block is for reporting at the end only */
char mes[2160]; /* Any message: this is really not clever hardcoding. For many disks this will cause a crash */
int dev = 1;
int disk;
size_t length;
varlel *varele;
/* Count the number of entries in the varylist */
npar = 0;
maxmod = 0;
nextvarlel = fit -> varylist;
while ((nextvarlel)) {
++npar;
if (nextvarlel -> moderate > maxmod)
maxmod = nextvarlel -> moderate;
nextvarlel = nextvarlel -> next;
}
/* Now ensure that the indexed parameters are aligned */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = chkchangep(fit -> varylist, fit -> fitmode, i, rpm -> nur);
/* When starting make one run of interpover, but first ensure a proper interpolation of the indexed parameters */
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
interpover(rpm, rpm -> radsep, 0, NULL, fit -> index);
/* The degrees of freedom are determined by the amount of variable
parameters, we do it VERY roughly. If there is a parameter varied
twice, this is not true anymore. Independent pixels are
determined by the assumption that HPBW in v is two pixels */
indpoints = (double) (hdr -> bsize1*hdr -> bsize2*hdr -> nsubs)/(CONVTHREEDBEAM*hdr -> bmaj*hdr -> bmin);
gft_mst_put(fit -> gft_mstv, &indpoints, GFT_INPUT_INDPOINTS);
/* Get the number of function calls per iteration */
hereiter = fit -> callite;
gft_mst_put(fit -> gft_mstv, &hereiter, GFT_INPUT_NCALLS_ST);
/* Do the first initialisation */
gft_mst_act(fit -> gft_mstv, GFT_ACT_INIT);
/* Now check if there are enough loops, iterations, and parameters to fit */
if (npar > 0 && fit -> loops > 0 && fit -> maxiter > 0) {
/* allocate */
if (!(dblarray = (double *) malloc(npar*sizeof(double))))
goto error;
/* The stopsize is 1 */
*dblarray = fit -> size;
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_STOPSIZE);
/* Get the number of total iterations left to be made */
hereiter = fit -> maxiter;
gft_mst_put(fit -> gft_mstv, &hereiter, GFT_INPUT_NITERS);
/* PSWARM input */
if (fit -> fitmode == PSWARM) {
anintege = fit -> psse; gft_mst_put(fit -> gft_mstv, &anintege, GFT_INPUT_SEED );
anintege = fit -> psnp; gft_mst_put(fit -> gft_mstv, &anintege, GFT_INPUT_PSNPART);
*dblarray = fit -> psco; gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_PSCOGNI);
*dblarray = fit -> psso; gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_PSSOCIA);
*dblarray = fit -> psmv; gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_PSMAXVF);
anintege = fit -> psnf; gft_mst_put(fit -> gft_mstv, &anintege, GFT_INPUT_PSNITFI);
*dblarray = fit -> psii; gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_PSINIIN);
*dblarray = fit -> psfi; gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_PSFININ);
*dblarray = fit -> psid; gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_PSINCDE);
*dblarray = fit -> psdd; gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_PSDECDE);
}
/* As long as there is moderation, we do this */
while (fit -> loopnr <= fit -> loops && fit -> loopnr <= maxmod) {
/* The first guess is in rpm -> par */
nextvarlel = fit -> varylist;
i = 0;
while (nextvarlel) {
dblarray[i] = rpm -> par[nextvarlel -> elements[0]];
nextvarlel = nextvarlel -> next;
++i;
}
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_SPAR);
/* Choose the origin to be identical */
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_OPAR);
/* Calculate the start deltas */
nextvarlel = fit -> varylist;
i = 0;
while (nextvarlel) {
dblarray[i] = fit -> loopnr <= nextvarlel -> moderate?((double) (fit -> loopnr - 1))*(nextvarlel -> delend - nextvarlel -> delstart)/((double) nextvarlel -> moderate)+nextvarlel -> delstart:nextvarlel -> delend;
nextvarlel = nextvarlel -> next;
++i;
}
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_DPAR);
/* Calculate the satisfaction deltas or grid normalisation */
/* ERROR SOURCE: This is done many times, but positioning it in front of the loops will lead to a segfault. This is a noted but in gft */
nextvarlel = fit -> varylist;
i = 0;
while (nextvarlel) {
dblarray[i] = nextvarlel -> mindelta;
nextvarlel = nextvarlel -> next;
++i;
}
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_NDPAR);
/* Put the number of loops to 1 */
asize_t = 1;
gft_mst_put(fit -> gft_mstv, &asize_t, GFT_INPUT_LOOPS);
/* Now DO it */
gft_mst_act(fit -> gft_mstv, GFT_ACT_START);
/* At the end, in this loop, copy the results to the parameters */
gft_mst_get(fit -> gft_mstv, dblarray, GFT_OUTPUT_SOLPAR);
nextvarlel = fit -> varylist;
j = 0;
while ((nextvarlel)) {
change = dblarray[j] - rpm -> par[nextvarlel -> elements[0]];
/* Every adressant of elements will be changed by the same amount */
for (i = 0; i < nextvarlel -> nelem; ++i)
rpm -> par[nextvarlel -> elements[i]] = rpm -> par[nextvarlel -> elements[i]]+change;
++j;
nextvarlel = nextvarlel -> next;
}
/* BUGFIX: change this according to the current solution */
for (i = rpm -> nur*NSSDPARAMS; i < rpm ->nur *(NSSDPARAMS+NDPARAMS*rpm -> ndisks); ++i)
rpm -> chapar[i] = chkchangep(fit -> varylist, fit -> fitmode, i, rpm -> nur);
/* rpm -> chapar[i] = 1; */
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
++fit -> loopnr;
}
/* The rest of the loops is run within the gft, possibly getting errors */
if (fit -> loopnr <= fit -> loops) {
/* The first guess is in rpm -> par */
nextvarlel = fit -> varylist;
i = 0;
while (nextvarlel) {
dblarray[i] = rpm -> par[nextvarlel -> elements[0]];
nextvarlel = nextvarlel -> next;
++i;
}
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_SPAR);
/* Choose the origin to be identical */
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_OPAR);
/* Get the start deltas */
nextvarlel = fit -> varylist;
i = 0;
while (nextvarlel) {
dblarray[i] = nextvarlel -> delend;
nextvarlel = nextvarlel -> next;
++i;
}
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_DPAR);
/* Calculate the satisfaction deltas or grid normalisation */
/* ERROR SOURCE: This is done many times, but positioning it in front of the loops will lead to a segfault. This is a noted but in gft */
nextvarlel = fit -> varylist;
i = 0;
while (nextvarlel) {
dblarray[i] = nextvarlel -> mindelta;
nextvarlel = nextvarlel -> next;
++i;
}
gft_mst_put(fit -> gft_mstv, dblarray, GFT_INPUT_NDPAR);
/* Put the number of loops to the remaining number of loops */
asize_t = fit -> loops - fit -> loopnr+1;
gft_mst_put(fit -> gft_mstv, &asize_t, GFT_INPUT_LOOPS);
/* Now DO it */
gft_mst_act(fit -> gft_mstv, GFT_ACT_START);
}
}
else {
/* No iterations have been made, which means that we have to do something */
i = gft_mst_act(fit -> gft_mstv, GFT_ACT_INIT);
/* Some initialisation here? */
gft_mst_get(fit -> gft_mstv, &fit -> mon_alloops , GFT_OUTPUT_ALLOOPS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_niters , GFT_OUTPUT_NITERS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_iters , GFT_OUTPUT_ITERS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_alliter , GFT_OUTPUT_ALLITER);
gft_mst_get(fit -> gft_mstv, &fit -> mon_allcalls , GFT_OUTPUT_ALLCALLS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_calls_st , GFT_OUTPUT_CALLS_ST);
gft_mst_get(fit -> gft_mstv, &fit -> mon_ncalls_st , GFT_OUTPUT_NCALLS_ST);
gft_mst_get(fit -> gft_mstv, &fit -> mon_npar_cur , GFT_OUTPUT_NPAR_CUR);
gft_mst_get(fit -> gft_mstv, &fit -> mon_dsize , GFT_OUTPUT_DSIZE);
gft_mst_get(fit -> gft_mstv, fit -> mon_dpar , GFT_OUTPUT_NDPAR);
gft_mst_get(fit -> gft_mstv, &fit -> mon_stopsize , GFT_OUTPUT_STOPSIZE);
fit -> mon_maxiter = fit -> maxiter;
fit -> mon_loops = fit -> loops;
varele = fit -> varylist;
i = 0;
if (fit -> mon_npar_cur > -1) {
while (i < fit -> mon_npar_cur) {
varele = varele -> next;
++i;
}
ftstab_putcoltitl(fit -> mon_key, (*varele -> elements)/rpm -> nur+1);
}
else {
sprintf(fit -> mon_key,"GEN");
}
fit -> mon_dsize = ddinterntoparam(fit -> mon_dsize, (*varele -> elements)/rpm -> nur+1, hdr, rpm -> ndisks);
for (k = 0; k < fit -> mon_npar; ++k) {
fit -> mon_dpar[k] = ddinterntoparam(fit -> mon_dpar[k], (*varele -> elements)/rpm -> nur+1, hdr, rpm -> ndisks);
}
fit -> mon_ring = (*varele -> elements)%rpm -> nur+1;
for (disk = 0; disk < rpm -> ndisks; ++disk){
fit -> mon_repnpoints[disk] = fit -> npoints[disk];
fit -> mon_totalflux[disk] = fit -> fluxpoints[disk]*rpm -> cflux[disk]*hdr -> deltgridtouser[2];
}
}
/* Report */
/* Find the chisquare of the latest iteration */
gft_mst_get(fit -> gft_mstv, &fit -> mon_bestchisq , GFT_OUTPUT_BESTCHISQ);
gft_mst_get(fit -> gft_mstv, &fit -> mon_actchisq , GFT_OUTPUT_ACTCHISQ);
gft_mst_get(fit -> gft_mstv, &fit -> mon_size , GFT_OUTPUT_SIZE);
if ((fit -> mon_allcalls)) {
/* find the right dpar */
if (fit -> mon_npar_cur > -1) {
dpar = fit -> mon_dpar[fit -> mon_npar_cur];
}
else {
dpar = fit -> mon_dpar[0];
}
sprintf(mes,
"L:%lu/%lu " /* loops/number of loops */
"I:%02lu/%.1E " /* iterations in loop/max iterations */
"M:%02lu/%.1E/%03lu " /* models in iteration / max models / total models / total models */
"P:%-6s " /* Parameter name */
"R:%02i " /* First ring number */
"A:%+.1E/%+.1E " /* Alteration in parameter, start change */
"N:%.1E", /* Number of pointsources */
(unsigned long) (fit -> mon_alloops+1), (unsigned long) fit -> mon_loops, /* loops run in total/final number of loops */
(unsigned long) fit -> mon_alliter+1, (double) fit -> mon_niters, /* iterations in loop/maximum iterations in loop */
(unsigned long) fit -> mon_calls_st+1, (double) fit -> mon_ncalls_st, (unsigned long) fit -> mon_allcalls, /* Models in loop/total models */
fit -> mon_key,
fit -> mon_ring,
fit -> mon_dsize,
dpar,
(double) fit -> mon_repnpoints[0]);
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%.1E", /* Number of pointsources */
(double) fit -> mon_repnpoints[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" F:%+.1E", /* Total flux */
fit -> mon_totalflux[0]);
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%+.1E",
fit -> mon_totalflux[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" C:%.3E " /* current chisquare */
/* "B:%.3E " */ /* current best (solution) chisquare */
"S:%+.1E", /* Current size */
fit -> mon_actchisq, /* current chisquare */
/* fit -> mon_bestchisq, */ /* current minimum chisquare */
fit -> mon_size /* Current size */
);
}
else {
sprintf(mes, "Start\n");
}
anyout_tir(&dev, mes);
/*Output of a progress file Kamphuis addition */
progressout(startinfv, mes);
/* Now keep everything in mind for the final (This is not necessarily necessary, but we do it anyway) */
gft_mst_get(fit -> gft_mstv, &fit -> mon_alloops , GFT_OUTPUT_ALLOOPS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_niters , GFT_OUTPUT_NITERS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_iters , GFT_OUTPUT_ITERS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_alliter , GFT_OUTPUT_ALLITER);
gft_mst_get(fit -> gft_mstv, &fit -> mon_allcalls , GFT_OUTPUT_ALLCALLS);
gft_mst_get(fit -> gft_mstv, &fit -> mon_calls_st , GFT_OUTPUT_CALLS_ST);
gft_mst_get(fit -> gft_mstv, &fit -> mon_ncalls_st , GFT_OUTPUT_NCALLS_ST);
gft_mst_get(fit -> gft_mstv, &fit -> mon_npar_cur , GFT_OUTPUT_NPAR_CUR);
gft_mst_get(fit -> gft_mstv, &fit -> mon_dsize , GFT_OUTPUT_DSIZE);
gft_mst_get(fit -> gft_mstv, fit -> mon_dpar , GFT_OUTPUT_NDPAR);
gft_mst_get(fit -> gft_mstv, &fit -> mon_stopsize , GFT_OUTPUT_STOPSIZE);
fit -> mon_maxiter = fit -> maxiter;
fit -> mon_loops = fit -> loops;
varele = fit -> varylist;
i = 0;
if (fit -> mon_npar_cur > -1) {
while (i < fit -> mon_npar_cur) {
varele = varele -> next;
++i;
}
ftstab_putcoltitl(fit -> mon_key, (*varele -> elements)/rpm -> nur+1);
}
else {
sprintf(fit -> mon_key,"GEN");
}
fit -> mon_dsize = ddinterntoparam(fit -> mon_dsize, (*varele -> elements)/rpm -> nur+1, hdr, rpm -> ndisks);
for (k = 0; k < fit -> mon_npar; ++k) {
fit -> mon_dpar[k] = ddinterntoparam(fit -> mon_dpar[k], (*varele -> elements)/rpm -> nur+1, hdr, rpm -> ndisks);
}
fit -> mon_ring = (*varele -> elements)%rpm -> nur+1;
for (disk = 0; disk < rpm -> ndisks; ++disk) {
fit -> mon_repnpoints[disk] = fit -> npoints[disk];
fit -> mon_totalflux[disk] = fit -> fluxpoints[disk]*rpm -> cflux[disk]*hdr -> deltgridtouser[2];
}
/* What has to be done is to get the output right, but this is done in putgenresults */
if ((dblarray))
free(dblarray);
return 1;
error:
if ((dblarray))
free(dblarray);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* function passed to gft */
static double gchsq_gen_start(double *vector, void *rest)
{
double gchsq_genv;
double chimult;
int i;
varlel *varele;
int disk;
/************************/
/************************/
adar *adarv;
/************************/
/* We get all the info from the additional arguments */
adarv = (adar *) rest;
/* Change them */
/* If they get out of range, we multiply the chisquare by OUTRANGEFAC */
chimult = pow(OUTRANGEFAC,chprm_gen(vector, adarv -> fit -> varylist, adarv -> rpm -> par));
/* Now ensure that the indexed parameters are aligned */
for (i = adarv -> rpm -> nur*NSSDPARAMS; i < adarv -> rpm ->nur *(NSSDPARAMS+NDPARAMS*adarv -> rpm -> ndisks); ++i)
adarv -> rpm -> chapar[i] = 1;
if (changedependent(adarv -> rpm, adarv -> rpm -> par, adarv -> fit -> index, adarv -> rpm -> chapar) < 0)
goto error;
/* When starting make one run of interpover */
interpover(adarv -> rpm, adarv -> rpm -> radsep, 1, NULL, adarv -> fit -> index);
/* Do make the model */
galmod(adarv -> hdr, adarv -> rpm, GENFIT, adarv -> fit -> varylist, adarv -> fit -> index, adarv -> fit -> fluxpoints, adarv -> fit -> npoints);
/* Get the chisquare, formerly using PCONDISP (NPARAMS + (ndisks - 1)*NDPARAMS) */
gchsq_genv = getchisquare_c(adarv -> rpm -> par[((NPARAMS + (adarv -> rpm -> ndisks - 1)*NDPARAMS))*adarv -> rpm -> nur]);
/* Regularise and get alloops first */
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alloops , GFT_OUTPUT_ALLOOPS);
gchsq_genv = reg_do(adarv -> fit -> reg_contv, (adarv -> fit -> mon_alloops == adarv -> fit -> loops)?adarv -> fit -> loops - 1:adarv -> fit -> mon_alloops, gchsq_genv);
/* Correct the chisquare taking into account the outliers */
adarv -> hdr -> chi2 = chimult*(gchsq_genv+((double) adarv -> rpm -> outpoints)*adarv -> rpm -> penalty);
/* Now keep everything in mind for the next iteration */
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alloops , GFT_OUTPUT_ALLOOPS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_niters , GFT_OUTPUT_NITERS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_iters , GFT_OUTPUT_ITERS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alliter , GFT_OUTPUT_ALLITER);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_allcalls , GFT_OUTPUT_ALLCALLS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_calls_st , GFT_OUTPUT_CALLS_ST);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_ncalls_st , GFT_OUTPUT_NCALLS_ST);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_npar_cur , GFT_OUTPUT_NPAR_CUR);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_bestchisq , GFT_OUTPUT_BESTCHISQ);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_actchisq , GFT_OUTPUT_ACTCHISQ);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_dsize , GFT_OUTPUT_DSIZE);
gft_mst_get(adarv -> fit -> gft_mstv, adarv -> fit -> mon_dpar , GFT_OUTPUT_DPAR);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_stopsize , GFT_OUTPUT_STOPSIZE);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_size , GFT_OUTPUT_SIZE);
adarv -> fit -> mon_maxiter = adarv -> fit -> maxiter;
adarv -> fit -> mon_loops = adarv -> fit -> loops;
varele = adarv -> fit -> varylist;
i = 0;
if (adarv -> fit -> mon_npar_cur > -1) {
while (i < adarv -> fit -> mon_npar_cur) {
varele = varele -> next;
++i;
}
ftstab_putcoltitl(adarv -> fit -> mon_key, (*varele -> elements)/adarv -> rpm -> nur+1);
}
else {
sprintf(adarv -> fit -> mon_key,"GEN");
}
adarv -> fit -> mon_dsize = ddinterntoparam(adarv -> fit -> mon_dsize, (*varele -> elements)/adarv -> rpm -> nur+1, adarv -> hdr, adarv -> rpm -> ndisks);
for (i = 0; i < adarv -> fit -> mon_npar; ++i) {
adarv -> fit -> mon_dpar[i] = ddinterntoparam(adarv -> fit -> mon_dpar[i], (*varele -> elements)/adarv -> rpm -> nur+1, adarv -> hdr, adarv -> rpm -> ndisks);
}
adarv -> fit -> mon_ring = (*varele -> elements)%adarv -> rpm -> nur+1;
for (disk = 0; disk < adarv -> rpm -> ndisks; ++disk){
adarv -> fit -> mon_repnpoints[disk] = adarv -> fit -> npoints[disk];
adarv -> fit -> mon_totalflux[disk] = adarv -> fit -> fluxpoints[disk]*adarv -> rpm -> cflux[disk]*adarv -> hdr -> deltgridtouser[2];
}
/* Change the fitting function */
i = gft_mst_putf(adarv -> fit -> gft_mstv, &gchsq_gen, GFT_INPUT_GCHSQ_REP);
return adarv -> hdr -> chi2;
error:
return -1.0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* function passed to gft */
static double gchsq_gen(double *vector, void *rest)
{
char mes[160]; /* Any message */
int dev = 1;
double gchsq_genv;
size_t length;
/* double chimult; */
double dpar;
varlel *varele;
int i,k;
int disk;
/************************/
/************************/
adar *adarv;
/************************/
/* We get all the info from the additional arguments */
adarv = (adar *) rest;
/* We read from the logfile */
if (ftstab_get_value(adarv -> fit -> recnr+1L, 1L, &gchsq_genv)) {
/* Find the chisquare of the latest iteration */
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_bestchisq , GFT_OUTPUT_BESTCHISQ);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_actchisq , GFT_OUTPUT_ACTCHISQ);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_size , GFT_OUTPUT_SIZE);
/* report what we have, if textlog, we assume that it has been written already */
if (!(adarv -> fit -> recnr)) {
sprintf(mes, "Start recalling\n");
anyout_tir(&dev, mes);
adarv -> fit -> mon_dsize = 0;
}
/* Now find dpar */
if (adarv -> fit -> mon_npar_cur > -1) {
dpar = adarv -> fit -> mon_dpar[adarv -> fit -> mon_npar_cur];
}
else {
dpar = adarv -> fit -> mon_dpar[0];
}
sprintf(mes,
"L:%lu/%lu " /* loops/number of loops */
"I:%02lu/%.1E " /* iterations in loop/max iterations */
"M:%02lu/%.1E/%03lu " /* models in iteration / max models / total models / total models */
"P:%-6s " /* Parameter name */
"R:%02i " /* First ring number */
"A:%+.1E/%+.1E ", /* Alteration in parameter, start change */
(unsigned long) (adarv -> fit -> mon_alloops+1), (unsigned long) adarv -> fit -> mon_loops, /* loops run in total/final number of loops */
(unsigned long) adarv -> fit -> mon_alliter+1, (double) adarv -> fit -> mon_niters, /* iterations in loop/maximum iterations in loop */
(unsigned long) adarv -> fit -> mon_calls_st+1, (double) adarv -> fit -> mon_ncalls_st, (unsigned long) adarv -> fit -> mon_allcalls, /* Models in loop/total models */
adarv -> fit -> mon_key,
adarv -> fit -> mon_ring,
adarv -> fit -> mon_dsize,
dpar);
length = strlen(mes);
sprintf(mes+length,
" C:%.9E " /* current chisquare */
/* "B:%.3E " */ /* current best (solution) chisquare */
"S:%+.1E", /* Current size */
adarv -> fit -> mon_actchisq, /* current chisquare */
/* adarv -> fit -> mon_bestchisq, */ /* current minimum chisquare */
adarv -> fit -> mon_size /* Current size */
);
anyout_tir(&dev, mes);
/*Output of a progress file Kamphuis addition */
progressout(adarv -> startinfv, mes);
/* Change them */
/* chimult = pow(OUTRANGEFAC,chprm_gen(vector, adarv -> fit -> varylist, adarv -> rpm -> par)); */
pow(OUTRANGEFAC,chprm_gen(vector, adarv -> fit -> varylist, adarv -> rpm -> par));
/* if (chprm_gen(vector, adarv -> fit -> varylist, adarv -> rpm -> par)) */
/* If they get out of range, we multiply the chisquare by OUTRANGEFAC */
/* chimult = OUTRANGEFAC; */
/* else */
/* chimult = 1.0; */
/* Now ensure that the indexed parameters are aligned */
for (i = adarv -> rpm -> nur*NSSDPARAMS; i < adarv -> rpm->nur *(NSSDPARAMS+NDPARAMS*adarv -> rpm->ndisks); ++i) {
adarv -> rpm -> chapar[i] = chkchangep(adarv -> fit -> varylist, adarv -> fit -> fitmode, i, adarv -> rpm -> nur);
}
if (changedependent(adarv -> rpm, adarv -> rpm -> par, adarv -> fit -> index, adarv -> rpm -> chapar) < 0)
goto error;
/* Do make the model */
/* galmod(adarv -> hdr, adarv -> rpm, GENFIT, adarv -> fit -> varylist, adarv -> fit -> index, fluxpoints, adarv -> fit -> npoints); */
/* Get the chisquare */
/* gchsq_genv = getchisquare_c(adarv -> rpm -> par[((NPARAMS + (adarv -> rpm -> ndisks - 1)*NDPARAMS))*adarv -> rpm -> nur]); */
/* Correct the chisquare taking into account the outliers */
adarv -> hdr -> chi2 = adarv -> hdr -> oldchi2 = gchsq_genv;
/* Now change this for the next iteration */
/* for (disk = 0; disk < rpm -> ndisks; ++disk) { */
/* adarv -> fit -> fluxpoints[disk] = fluxpoints[disk]; */
/* } */
++adarv -> fit -> recnr;
/* Produce output */
writeoutputread(adarv -> log, adarv -> hdr, adarv -> rpm, adarv -> fit, 0, adarv -> fit -> dof, adarv -> fit -> recnr, -1.0);
/* Now keep everything in mind for the next iteration */
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alloops , GFT_OUTPUT_ALLOOPS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_niters , GFT_OUTPUT_NITERS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_iters , GFT_OUTPUT_ITERS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alliter , GFT_OUTPUT_ALLITER);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_allcalls , GFT_OUTPUT_ALLCALLS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_calls_st , GFT_OUTPUT_CALLS_ST);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_ncalls_st , GFT_OUTPUT_NCALLS_ST);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_npar_cur , GFT_OUTPUT_NPAR_CUR);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_dsize , GFT_OUTPUT_DSIZE);
gft_mst_get(adarv -> fit -> gft_mstv, adarv -> fit -> mon_dpar , GFT_OUTPUT_NDPAR);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_stopsize , GFT_OUTPUT_STOPSIZE);
adarv -> fit -> mon_maxiter = adarv -> fit -> maxiter;
adarv -> fit -> mon_loops = adarv -> fit -> loops;
varele = adarv -> fit -> varylist;
i = 0;
if (adarv -> fit -> mon_npar_cur > -1) {
while (i < adarv -> fit -> mon_npar_cur) {
varele = varele -> next;
++i;
}
ftstab_putcoltitl(adarv -> fit -> mon_key, (*varele -> elements)/adarv -> rpm -> nur+1);
}
else {
sprintf(adarv -> fit -> mon_key,"GEN");
}
adarv -> fit -> mon_dsize = ddinterntoparam(adarv -> fit -> mon_dsize, (*varele -> elements)/adarv -> rpm -> nur+1, adarv -> hdr, adarv -> rpm -> ndisks);
for (k = 0; k < adarv -> fit -> mon_npar; ++k) {
adarv -> fit -> mon_dpar[k] = ddinterntoparam(adarv -> fit -> mon_dpar[k], (*varele -> elements)/adarv -> rpm -> nur+1, adarv -> hdr, adarv -> rpm -> ndisks);
}
adarv -> fit -> mon_ring = (*varele -> elements)%adarv -> rpm -> nur+1;
for (disk = 0; disk < adarv -> rpm -> ndisks; ++disk){
adarv -> fit -> mon_repnpoints[disk] = adarv -> fit -> npoints[disk];
adarv -> fit -> mon_totalflux[disk] = adarv -> fit -> fluxpoints[disk]*adarv -> rpm -> cflux[disk]*adarv -> hdr -> deltgridtouser[2];
}
}
else {
/* ERROR SOURCE: Some initialisation here ? */
gchsq_genv = gchsq_gen2(vector, rest);
/* Change the fitting function */
gft_mst_putf(adarv -> fit -> gft_mstv, &gchsq_gen2, GFT_INPUT_GCHSQ_REP);
}
return gchsq_genv;
error:
return -1.0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* function passed to gft */
static double gchsq_gen2(double *vector, void *rest)
{
char mes[260]; /* Any message */
int dev = 1;
double gchsq_genv = 0;
double chimult;
double dpar;
int i,k;
int disk;
size_t length;
varlel *varele;
/************************/
/************************/
adar *adarv;
/************************/
/* We get all the info from the additional arguments */
adarv = (adar *) rest;
/* Find the chisquare of the latest iteration */
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_bestchisq , GFT_OUTPUT_BESTCHISQ);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_actchisq , GFT_OUTPUT_ACTCHISQ);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_size , GFT_OUTPUT_SIZE);
/* report what we have, if textlog, we assume that it has been written already */
if (!(adarv -> fit -> mon_allcalls)) {
sprintf(mes, "Start\n");
anyout_tir(&dev, mes);
adarv -> fit -> mon_dsize = 0;
}
/* Now find dpar */
if (adarv -> fit -> mon_npar_cur > -1) {
dpar = adarv -> fit -> mon_dpar[adarv -> fit -> mon_npar_cur];
}
else {
dpar = adarv -> fit -> mon_dpar[0];
}
sprintf(mes,
"L:%lu/%lu " /* loops/number of loops */
"I:%02lu/%.1E " /* iterations in loop/max iterations */
"M:%02lu/%.1E/%03lu " /* models in iteration / max models / total models / total models */
"P:%-6s " /* Parameter name */
"R:%02i " /* First ring number */
"A:%+.1E/%+.1E " /* Alteration in parameter, start change */
"N:%.1E", /* Number of pointsources */
(unsigned long) (adarv -> fit -> mon_alloops+1), (unsigned long) adarv -> fit -> mon_loops, /* loops run in total/final number of loops */
(unsigned long) adarv -> fit -> mon_alliter+1, (double) adarv -> fit -> mon_niters, /* iterations in loop/maximum iterations in loop */
(unsigned long) adarv -> fit -> mon_calls_st+1, (double) adarv -> fit -> mon_ncalls_st, (unsigned long) adarv -> fit -> mon_allcalls, /* Models in loop/total models */
adarv -> fit -> mon_key,
adarv -> fit -> mon_ring,
adarv -> fit -> mon_dsize,
dpar,
(double) adarv -> fit -> mon_repnpoints[0]);
for (disk = 1; disk < adarv -> rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%.1E", /* Number of pointsources */
(double) adarv -> fit -> mon_repnpoints[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" F:%+.1E", /* Total flux */
adarv -> fit -> mon_totalflux[0]);
for (disk = 1; disk < adarv -> rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%+.1E",
adarv -> fit -> mon_totalflux[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" C:%.7E " /* current chisquare */
/* "B:%.3E " */ /* current best (solution) chisquare */
"S:%+.1E", /* Current size */
adarv -> fit -> mon_actchisq, /* current chisquare */
/* adarv -> fit -> mon_bestchisq, */ /* current minimum chisquare */
adarv -> fit -> mon_size /* Current size */
);
anyout_tir(&dev, mes);
/*Output of a progress file Kamphuis addition */
progressout(adarv -> startinfv, mes);
/* Change them */
chimult = pow(OUTRANGEFAC,chprm_gen(vector, adarv -> fit -> varylist, adarv -> rpm -> par));
/* if (chprm_gen(vector, adarv -> fit -> varylist, adarv -> rpm -> par)) */
/* If they get out of range, we multiply the chisquare by OUTRANGEFAC */
/* chimult = OUTRANGEFAC; */
/* else */
/* chimult = 1.0; */
/* Now ensure that the indexed parameters are aligned */
for (i = adarv -> rpm -> nur*NSSDPARAMS; i < adarv -> rpm->nur *(NSSDPARAMS+NDPARAMS*adarv -> rpm->ndisks); ++i)
adarv -> rpm -> chapar[i] = chkchangep(adarv -> fit -> varylist, adarv -> fit -> fitmode, i, adarv -> rpm -> nur);
if (changedependent(adarv -> rpm, adarv -> rpm -> par, adarv -> fit -> index, adarv -> rpm -> chapar) < 0)
goto error;
/* Do make the model */
galmod(adarv -> hdr, adarv -> rpm, GENFIT, adarv -> fit -> varylist, adarv -> fit -> index, adarv -> rpm -> fluxpoints, adarv -> fit -> npoints);
/* Get the chisquare, formerly using pcondisp */
gchsq_genv = getchisquare_c(adarv -> rpm -> par[((NPARAMS + (adarv -> rpm -> ndisks - 1)*NDPARAMS))*adarv -> rpm -> nur]);
/* Regularise */
/* First recall the loop number, keep everything in mind for the next iteration */
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alloops , GFT_OUTPUT_ALLOOPS);
gchsq_genv = reg_do(adarv -> fit -> reg_contv, (adarv -> fit -> mon_alloops == adarv -> fit -> loops)?adarv -> fit -> loops - 1:adarv -> fit -> mon_alloops, gchsq_genv);
/* Correct the chisquare taking into account the outliers */
adarv -> hdr -> chi2 = chimult*(gchsq_genv+((double) adarv -> rpm -> outpoints)*adarv -> rpm -> penalty);
/* Now change this for the next iteration */
for (disk = 0; disk < adarv -> rpm -> ndisks; ++disk) {
adarv -> fit -> fluxpoints[disk] = adarv -> rpm -> fluxpoints[disk];
}
++adarv -> fit -> recnr;
/* Write an output cube */
if ((*adarv -> hdr -> outset != '\0')) {
if (!(adarv -> fit -> recnr%adarv -> hdr -> outcubup)) {
/* for (i = 0; i < adarv -> rpm -> nur*(NPARAMS+(adarv -> rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i) */
/* adarv -> rpm -> oldpar[i] = adarv -> rpm -> par[i]; */
writemodel(adarv -> hdr, adarv -> rpm, adarv -> fit, adarv -> rpm -> par, adarv -> fit -> index);
}
}
/* Produce output */
adarv -> hdr -> oldchi2 = adarv -> hdr -> chi2;
/* correct this fitting */
writeoutput(adarv -> log, adarv -> hdr, adarv -> rpm, adarv -> fit, 0, adarv -> fit -> dof, adarv -> fit -> recnr, -1.0);
/* Read out the same number, it might have changed by an epsilon */
gchsq_genv = adarv -> hdr -> oldchi2;
/* Correct this fitting */
gchsq_genv = 1.0;
ftstab_get_value(adarv -> fit -> recnr, 1L, &gchsq_genv);
/* Now keep everything in mind for the next iteration */
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alloops , GFT_OUTPUT_ALLOOPS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_niters , GFT_OUTPUT_NITERS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_iters , GFT_OUTPUT_ITERS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_alliter , GFT_OUTPUT_ALLITER);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_allcalls , GFT_OUTPUT_ALLCALLS);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_calls_st , GFT_OUTPUT_CALLS_ST);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_ncalls_st , GFT_OUTPUT_NCALLS_ST);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_npar_cur , GFT_OUTPUT_NPAR_CUR);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_dsize , GFT_OUTPUT_DSIZE);
gft_mst_get(adarv -> fit -> gft_mstv, adarv -> fit -> mon_dpar , GFT_OUTPUT_NDPAR);
gft_mst_get(adarv -> fit -> gft_mstv, &adarv -> fit -> mon_stopsize , GFT_OUTPUT_STOPSIZE);
adarv -> fit -> mon_maxiter = adarv -> fit -> maxiter;
adarv -> fit -> mon_loops = adarv -> fit -> loops;
varele = adarv -> fit -> varylist;
i = 0;
if (adarv -> fit -> mon_npar_cur > -1) {
while (i < adarv -> fit -> mon_npar_cur) {
varele = varele -> next;
++i;
}
ftstab_putcoltitl(adarv -> fit -> mon_key, (*varele -> elements)/adarv -> rpm -> nur+1);
}
else {
sprintf(adarv -> fit -> mon_key,"GEN");
}
adarv -> fit -> mon_dsize = ddinterntoparam(adarv -> fit -> mon_dsize, (*varele -> elements)/adarv -> rpm -> nur+1, adarv -> hdr, adarv -> rpm -> ndisks);
for (k = 0; k < adarv -> fit -> mon_npar; ++k) {
adarv -> fit -> mon_dpar[k] = ddinterntoparam(adarv -> fit -> mon_dpar[k], (*varele -> elements)/adarv -> rpm -> nur+1, adarv -> hdr, adarv -> rpm -> ndisks);
}
adarv -> fit -> mon_ring = (*varele -> elements)%adarv -> rpm -> nur+1;
for (disk = 0; disk < adarv -> rpm -> ndisks; ++disk){
adarv -> fit -> mon_repnpoints[disk] = adarv -> fit -> npoints[disk];
adarv -> fit -> mon_totalflux[disk] = adarv -> fit -> fluxpoints[disk]*adarv -> rpm -> cflux[disk]*adarv -> hdr -> deltgridtouser[2];
}
return gchsq_genv;
error:
return -1.0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Interpolate over the par list to get the modpar */
static void interpinit(ringparms *rpm, double radsep, int disk)
{
int i,j,jp,k;
/* float width; */
/* float dpardr[NPARAMS]; */
/* float dr; */
int n2, n1;
/* In the modpar array interpolate over all rings */
for (i = 1; i < rpm -> nur; ++i) {
/* This is the actual width between two radii */
/* Obsolete when using GSL */
/* width = rpm -> par[PRADI*rpm -> nur+i] - rpm -> par[PRADI*rpm -> nur+i-1]; */
/* These are the rings to be calculated */
n2 = (int) (rpm -> par[PRADI*rpm -> nur+i]/radsep-0.5);
n1 = ((int) (rpm -> par[PRADI*rpm -> nur+i-1]/radsep+0.5));
/* in-between two rings, the slope is determined */
/* for (j = NPARAMS+(disk-1)*NDPARAMS; j < NPARAMS+disk*NDPARAMS; ++j) { */
for (jp = NPARAMS-NDPARAMS; jp < NPARAMS; ++jp) {
j = jp + disk*NDPARAMS;
/* If the parameter is in the list */
/* Obsolete when using GSL */
/* dpardr[jp]= (rpm -> par[j*rpm -> nur+i]-rpm -> par[j*rpm -> nur+i-1])/width; */
/* Not sure if this is required, but do it anyway */
gsl_interp_accel_reset(rpm -> gsl_interp_accelarray[j-NSSDPARAMS]);
/* Very sure that this is a requirement; a test has shown that this should be ouside an omp pragma, not sure why */
gsl_interp_init(rpm -> gsl_interparray[j-NSSDPARAMS],rpm -> par+PRADI*rpm -> nur, rpm -> par + rpm -> nur*j, rpm -> nur);
}
/* D*mn GSL! GSL interpolation is not compatible with OMP anyway */
/* #ifdef OPENMPTIR */
/* #pragma omp parallel for schedule(dynamic) */
/* #endif */
for (jp = NPARAMS-NDPARAMS; jp < NPARAMS; ++jp) {
j = jp + disk*NDPARAMS;
/* If the parameter is in the list */
/* Obsolete when using GSL */
/* dpardr[jp]= (rpm -> par[j*rpm -> nur+i]-rpm -> par[j*rpm -> nur+i-1])/width; */
/* Not sure if this is required, but do it anyway */
gsl_interp_accel_reset(rpm -> gsl_interp_accelarray[j-NSSDPARAMS]);
/* Very sure that this is a requirement; a test has shown */
gsl_interp_init(rpm -> gsl_interparray[j-NSSDPARAMS],rpm -> par+PRADI*rpm -> nur, rpm -> par + rpm -> nur*j, rpm -> nur);
for (k = n1; k <= n2; ++k) {
/* for each parameter the intepolation is done */
rpm -> modpar[PRADI*rpm -> nr+k] = ((float) k)*radsep+radsep/2.0;
/* Obsolete when using GSL */
/* dr = rpm -> modpar[PRADI*rpm -> nr+k]-rpm -> par[PRADI*rpm -> nur+i-1]; */
/* rpm -> modpar[j*rpm -> nr+k] = rpm -> par[j*rpm -> nur+i-1]+dpardr[jp]*dr; */
/* if (k == n1) { */
/* fprintf(stderr,"Alpha j: %i n1: %i n2: %i %i %f %f\n",j,n1,n2,k,rpm -> modpar[PRADI*rpm -> nr+k],rpm -> par[PRADI*rpm -> nur+i-1]); */
/* } */
/* if (k == n2) { */
/* fprintf(stderr,"Omega %i %f %f\n",k,rpm -> modpar[PRADI*rpm -> nr+k],rpm -> par[PRADI*rpm -> nur+i]); */
/* } */
rpm -> modpar[j*rpm -> nr+k] = gsl_interp_eval(rpm -> gsl_interparray[j-NSSDPARAMS], rpm -> par+PRADI*rpm -> nur, rpm -> par + rpm -> nur*j, rpm -> modpar[PRADI*rpm -> nr+k], rpm -> gsl_interp_accelarray[j-NSSDPARAMS]);
}
}
/* Now change the pre-processed parameters and terminate the pointsource lists */
for (k = n1; k <= n2; ++k)
srprep(rpm, k, 0, disk);
}
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Interpolate over the par list to get the modpar */
static void interpover(ringparms *rpm, double radsep, int fitmode, varlel *varele, decomp_inlist *index)
{
int i,j,jp,k,disk;
/* float width; */
/* float dpardr[NPARAMS]; */
/* float dr; */
int n1, n2, s, e;
/* Check if we initialise */
if (!(varele)) {
for (disk = 0; disk < rpm -> ndisks; ++disk) {
interpinit(rpm, radsep, disk);
}
return;
}
/* Switch on all indicators right to a range that should be interpolated over, depending on interpolation method */
for (disk = 0; disk < rpm -> ndisks; ++disk) {
for (jp = 0; jp < NDPARAMS; ++jp) {
for (i = 1; i < rpm -> nur; ++i) {
if (rpm -> chapar[(NDPARAMS*disk+jp+NSSDPARAMS)*rpm -> nur+i])
break;
}
if (i < rpm -> nur) {
if (rpm -> smothcar[jp+disk*NDPARAMS] == INTERP_AKIMA) {
s = -2;
e = 4;
}
else if (rpm -> smothcar[jp+disk*NDPARAMS] == INTERP_CSPLINE) {
s = 1;
e = rpm -> nur;
}
else {
s = 1;
e = 2;
}
for (i = 0; i < rpm -> nur; ++i) {
if (rpm -> chapar[(NDPARAMS*disk+jp+NSSDPARAMS)*rpm -> nur+i] == 1) {
for (k = s; k < e; ++k) {
if ((k+i) >= rpm -> nur)
break;
if ((k+i) > -1) {
rpm -> chapar[(NDPARAMS*disk+jp+NSSDPARAMS)*rpm -> nur+k+i] = 2;
}
}
/* i = i+k; */
}
}
}
}
}
/* printf("paraf:"); */
/* for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i) */
/* if (rpm -> chapar[i]) */
/* printf(" %i", i); */
/* printf(" "); */
for (disk = 0; disk < rpm -> ndisks; ++disk) {
/* In the modpar array interpolate over all rings */
for (i = 1; i < rpm -> nur; ++i) {
/* These are the subrings to be calculated */
n2 = (int) (rpm -> par[PRADI*rpm -> nur+i]/radsep-0.5);
n1 = ((int) (rpm -> par[PRADI*rpm -> nur+i-1]/radsep+0.5));
/* D*mn GSL! GSL interpolation is not compatible with OMP anyway */
/* #ifdef OPENMPTIR */
/* #pragma omp parallel for schedule(dynamic) */
/* #endif */
for (jp = 0; jp < NDPARAMS; ++jp) {
j = NSSDPARAMS+jp+disk*NDPARAMS;
/* If the parameter is in the list */
if (rpm -> chapar[j*rpm -> nur+i]) {
/* Obsolete when using GSL */
/* dpardr[jp]= (rpm -> par[j*rpm -> nur+i]-rpm -> par[j*rpm -> nur+i-1])/width; */
/* GSL Re-initialise interpolation, don't know if required, but well ... */
gsl_interp_accel_reset(rpm -> gsl_interp_accelarray[j-NSSDPARAMS]);
for (k = n1; k <= n2; ++k) {
/* Obsolete when using GSL */
/* dr = rpm -> modpar[PRADI*rpm -> nr+k]-rpm -> par[PRADI*rpm -> nur+i-1]; */
/* for each parameter the intepolation is done */
/* Obsolete when using GSL */
/* rpm -> modpar[j*rpm -> nr+k] = rpm -> par[j*rpm -> nur+i-1]+dpardr[jp]*dr; */
rpm -> modpar[j*rpm -> nr+k] = gsl_interp_eval (rpm -> gsl_interparray[j-NSSDPARAMS], rpm -> par, rpm -> par + rpm -> nur*j, rpm -> modpar[PRADI*rpm -> nr+k], rpm -> gsl_interp_accelarray[j-NSSDPARAMS]);
}
/* Now change the pre-processed parameters and terminate the pointsource lists */
for (k = n1; k <= n2; ++k)
srprep(rpm, k, 0, disk);
}
}
}
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static void srprep(ringparms *rpm, int srnr, long mode, int disk)
{
(*(rpm -> inf_smiv[disk] -> srprsbrmax))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprb0))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprs1))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprs2))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprs3))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprs4))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprc1))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprc2))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprc3))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> srprc4))((void *) rpm, srnr, disk);
(*(rpm -> inf_gauv[disk] -> srpr0))((void *) rpm, srnr, 0, disk);
(*(rpm -> inf_gauv[disk] -> srpr1))((void *) rpm, srnr, 1, disk);
(*(rpm -> inf_gauv[disk] -> srpr2))((void *) rpm, srnr, 2, disk);
(*(rpm -> inf_gauv[disk] -> srpr3))((void *) rpm, srnr, 3, disk);
/* Reset the number of point sources */
rpm -> sd[disk][srnr].n =
rpm -> sd[disk][srnr].nneg =
rpm -> sd[disk][srnr].npos = 0;
rpm -> sd[disk][srnr].nharmnorm =
rpm -> sd[disk][srnr].ngaussian[0] =
rpm -> sd[disk][srnr].ngaussian[1] =
rpm -> sd[disk][srnr].ngaussian[2] =
rpm -> sd[disk][srnr].ngaussian[3] = 0;
/* Calculate the cloudnumber, rounded down; this will fill the harmnorm variables */
(*(rpm -> inf_smiv[disk] -> getcloudnumber))((void *) rpm, srnr, disk);
(*(rpm -> inf_gauv[disk] -> getcloudnumber0))((void *) rpm, srnr, 0, disk);
(*(rpm -> inf_gauv[disk] -> getcloudnumber1))((void *) rpm, srnr, 1, disk);
(*(rpm -> inf_gauv[disk] -> getcloudnumber2))((void *) rpm, srnr, 2, disk);
(*(rpm -> inf_gauv[disk] -> getcloudnumber3))((void *) rpm, srnr, 3, disk);
/* Change the number of point sources and the cloud flux */
(*(rpm -> inf_sdisv[disk] -> chclfl))((void *) rpm, srnr, disk);
rpm -> sd[disk][srnr].pllength = rpm -> sd[disk][srnr].n;
/* We decide to change the cloudflux a bit instead of accepting an error in the ringflux */
/* rpm -> sd[disk][srnr].pf = ringflux/rpm -> sd[disk][srnr].n; */
if (rpm -> sd[disk][srnr].n > 0) {
/* We calculate cos's and sins and reset the random number generator */
rpm -> sd[disk][srnr].sini=sinf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nr+srnr]);
rpm -> sd[disk][srnr].cosi=cosf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nr+srnr]);
rpm -> sd[disk][srnr].sinp=sinf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PPA)*rpm -> nr+srnr]);
rpm -> sd[disk][srnr].cosp=cosf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PPA)*rpm -> nr+srnr]);
/* prepare the subrings for harmonics info */
/* velocity */
(*(rpm -> inf_vm1v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_vm1v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_vm2v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_vm2v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_vm3v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_vm3v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_vm4v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_vm4v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra1v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra1v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra2v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra2v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra3v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra3v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra4v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ra4v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro1v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro1v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro2v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro2v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro3v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro3v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro4v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_ro4v[disk] -> srprc))((void *) rpm, srnr, disk);
/* warps */
(*(rpm -> inf_wm1v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_wm1v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_wm2v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_wm2v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_wm3v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_wm3v[disk] -> srprc))((void *) rpm, srnr, disk);
(*(rpm -> inf_wm4v[disk] -> srprs))((void *) rpm, srnr, disk);
(*(rpm -> inf_wm4v[disk] -> srprc))((void *) rpm, srnr, disk);
/* Azimuth ranges */
(*(rpm -> inf_aziv[disk] -> srpr0))((void *) rpm, srnr, 0, disk);
(*(rpm -> inf_aziv[disk] -> srpr1))((void *) rpm, srnr, 1, disk);
}
/* free the pointsource list */
if ((rpm -> sd[disk][srnr].pl)) {
free(rpm -> sd[disk][srnr].pl);
rpm -> sd[disk][srnr].pl = NULL;
}
#ifdef PBCORR
rpm -> dealloc_pbcfac(rpm, srnr, disk);
#endif
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Grids a point to a pointsource list */
#ifdef PBCORR
static void gridpoint_norm(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#else
static void gridpoint_norm(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#endif
{
int grid[3];
/* of course we could make it even shorter, but we'll leave it at that. Next thingy is to grid the pointsource */
grid[0] = roundnormal(modpar[(PRPARAMS+disk*NDPARAMS+PXPOS)*nr+srnr]-pp[1]);
if (grid[0] >= 0 && grid[0] < hdr -> bsize1) {
grid[1] = roundnormal(modpar[(PRPARAMS+disk*NDPARAMS+PYPOS)*nr+srnr]+pp[0]);
if (grid[1] >= 0 && grid[1] < hdr -> bsize2) {
/* */
grid[2] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PVSYS)*nr+srnr]+hdr -> signv*pp[5]));
/* grid[2] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PVSYS)*nr+srnr]+pp[4])); */
if (grid[2] >= 0 && grid[2] < hdr -> nsubs) {
/* This is the position in the linear cube array */
sd[disk][srnr].pl[*pnr] = hdr -> modelc -> points +(grid[0]+ hdr -> bcsize1*(grid[1])+hdr -> nprof*(grid[2]));
/* And this is for the primary beam correction */
#ifdef PBCORR
fill_pbcfac(hdr, sd, disk, srnr, pnr, grid);
#endif
++(*pnr);
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
}
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Grids a point to a pointsource list */
#ifdef PBCORR
static void gridpoint_mixed(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#else
static void gridpoint_mixed(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#endif
{
int grid[3];
/* of course we could make it even shorter, but we'll leave it at that. Next thingy is to grid the pointsource */
grid[0] = roundnormal(modpar[(PRPARAMS+disk*NDPARAMS+PXPOS)*nr+srnr]-pp[1]);
if (grid[0] >= 0 && grid[0] < hdr -> bsize1) {
grid[1] = roundnormal(modpar[(PRPARAMS+disk*NDPARAMS+PYPOS)*nr+srnr]+pp[0]);
if (grid[1] >= 0 && grid[1] < hdr -> bsize2) {
/* For the sake of clarity, we kill the subsnuma operation in the source, in principle thus allowing only for the radio convention for velocity, but gaining an understanding of the code. What is seen here should not be done. It's really not what anyone should wish for. */
grid[2] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PVSYS)*nr+srnr]+hdr -> signv*pp[5]));
/* grid[2] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PVSYS)*nr+srnr]+pp[4])); */
if (grid[2] >= 0 && grid[2] < hdr -> nsubs) {
/* This is the position in the linear cube array */
if (signum) {
sd[disk][srnr].pl[sd[disk][srnr].npos] = hdr -> modelc -> points +(grid[0]+ hdr -> bcsize1*(grid[1])+hdr -> nprof*(grid[2]));
++sd[disk][srnr].npos;
}
else {
++sd[disk][srnr].nneg;
sd[disk][srnr].pl[sd[disk][srnr].pllength-sd[disk][srnr].nneg] = hdr -> modelc -> points+(grid[0]+ hdr -> bcsize1*(grid[1])+hdr -> nprof*(grid[2]));
}
#ifdef PBCORR
fill_pbcfac(hdr, sd, disk, srnr, pnr, grid);
#endif
++(*pnr);
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
/* if (signum) { */
/* ++sd[disk][srnr].outnpos; */
/* } */
/* else { */
/* ++sd[disk][srnr].outnneg; */
/* } */
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
/* if (signum) { */
/* ++sd[disk][srnr].outnpos; */
/* } */
/* else { */
/* ++sd[disk][srnr].outnneg; */
/* } */
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
/* if (signum) { */
/* ++sd[disk][srnr].outnpos; */
/* } */
/* else { */
/* ++sd[disk][srnr].outnneg; */
/* } */
}
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Grids a point to a pointsource list */
#ifdef PBCORR
static void gridpoint_normcool(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#else
static void gridpoint_normcool(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#endif
{
int grid[3];
/* of course we could make it even shorter, but we'll leave it at that. Next thingy is to grid the pointsource */
grid[0] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PXPOS)*nr+srnr]-pp[1])*((float) hdr->coolbin));
if (grid[0] >= 0 && grid[0] < hdr -> coolcube -> size_x) {
grid[1] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PYPOS)*nr+srnr]+pp[0])*((float) hdr->coolbin));
if (grid[1] >= 0 && grid[1] < hdr -> coolcube -> size_y) {
/* */
grid[2] = roundnormal(hdr -> coolhalfc+pp[2]*((float) hdr->coolbin));
/* grid[2] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PVSYS)*nr+srnr]+pp[4])); */
if (grid[2] >= 0 && grid[2] < hdr -> coolcube -> size_v) {
/* This is the position in the linear cube array */
sd[disk][srnr].pl[*pnr] = hdr -> coolcube -> points +(grid[0]+ hdr -> coolcube -> size_x*(grid[1])+hdr -> nprofcool*(grid[2]));
/* And this is for the primary beam correction */
#ifdef PBCORR
fill_pbcfac(hdr, sd, disk, srnr, pnr, grid);
#endif
++(*pnr);
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
}
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Grids a point to a pointsource list */
#ifdef PBCORR
static void gridpoint_mixedcool(hdrinf *hdr, void (*fill_pbcfac)(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid), float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#else
static void gridpoint_mixedcool(hdrinf *hdr, float *modpar, int nr, struct srd **sd, int srnr, long *pnr, float *pp, int signum, long *npoints, int disk)
#endif
{
int grid[3];
/* of course we could make it even shorter, but we'll leave it at that. Next thingy is to grid the pointsource */
grid[0] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PXPOS)*nr+srnr]-pp[1])*((float) hdr->coolbin));
if (grid[0] >= 0 && grid[0] < hdr -> coolcube -> size_x) {
grid[1] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PYPOS)*nr+srnr]+pp[0])*((float) hdr->coolbin));
if (grid[1] >= 0 && grid[1] < hdr -> bsize2) {
/* For the sake of clarity, we kill the subsnuma operation in the source, in principle thus allowing only for the radio convention for velocity, but gaining an understanding of the code. What is seen here should not be done. It's really not what anyone should wish for. */
grid[2] = roundnormal(hdr -> coolhalfc+pp[2]*((float) hdr->coolbin));
/* grid[2] = roundnormal((modpar[(PRPARAMS+disk*NDPARAMS+PVSYS)*nr+srnr]+pp[4])); */
if (grid[2] >= 0 && grid[2] < hdr -> coolcube -> size_v) {
/* This is the position in the linear cube array */
if (signum) {
sd[disk][srnr].pl[sd[disk][srnr].npos] = hdr -> coolcube -> points +(grid[0]+ hdr -> coolcube -> size_x*(grid[1])+hdr -> nprofcool*(grid[2]));
++sd[disk][srnr].npos;
}
else {
++sd[disk][srnr].nneg;
sd[disk][srnr].pl[sd[disk][srnr].pllength-sd[disk][srnr].nneg] = hdr -> coolcube -> points+(grid[0]+ hdr -> coolcube -> size_x*(grid[1])+hdr -> nprofcool*(grid[2]));
}
#ifdef PBCORR
fill_pbcfac(hdr, sd, disk, srnr, pnr, grid);
#endif
++(*pnr);
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
/* if (signum) { */
/* ++sd[disk][srnr].outnpos; */
/* } */
/* else { */
/* ++sd[disk][srnr].outnneg; */
/* } */
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
/* if (signum) { */
/* ++sd[disk][srnr].outnpos; */
/* } */
/* else { */
/* ++sd[disk][srnr].outnneg; */
/* } */
}
}
else {
--sd[disk][srnr].n;
*npoints -= 1;
++sd[disk][srnr].outn;
/* if (signum) { */
/* ++sd[disk][srnr].outnpos; */
/* } */
/* else { */
/* ++sd[disk][srnr].outnneg; */
/* } */
}
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Grids a point to a pointsource list */
#ifdef PBCORR
static int srput_mixed(void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long grid), struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk)
#else
static int srput_mixed(struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk)
#endif
{
long i;
int negstop;
/* ringflux = TWOPI*modpar[PRADI*nr+srnr]*radsep*modpar[PSBR*nr+srnr]/cflux; */
/* Calculate the point source flux */
/* These lines are a nice idea, however, if the total surface density is close to zero, this becomes probably more inaccurate than what we've left */
/* if ((cloudsum = sd[disk][srnr].npos+sd[disk][srnr].outnpos-sd[disk][srnr].nneg-sd[disk][srnr].outnneg) > 0) { */
/* sd[disk][srnr].pf = TWOPI*modpar[PRADI*nr+srnr]*radsep*modpar[PSBR*nr+srnr]/fabs(cloudsum); */
/* } */
/* else */
/* Kamphuis bugfix */
/* sd[disk][srnr].pf = cflux[0]*sd[disk][srnr].nsubclinv; -> */
sd[disk][srnr].pf = cflux[disk]*sd[disk][srnr].nsubclinv;
/* if (!(sd[disk][srnr].pf)) */
/* sd[disk][srnr].pf = cflux[0]; */
#ifdef PBCORR
for (i = 0; i < sd[disk][srnr].npos; ++i)
corr_pbcfac(sd, disk, srnr, i);
#else
for (i = 0; i < sd[disk][srnr].npos; ++i)
*(sd[disk][srnr].pl[i]) += sd[disk][srnr].pf;
#endif
sd[disk][srnr].pf = -sd[disk][srnr].pf;
/* Here I don't trust the compiler a bit */
negstop = sd[disk][srnr].pllength-sd[disk][srnr].nneg-1;
#ifdef PBCORR
for (i = sd[disk][srnr].pllength-1; i > negstop; --i)
corr_pbcfac(sd, disk, srnr, i);
#else
for (i = sd[disk][srnr].pllength-1; i > negstop; --i)
*(sd[disk][srnr].pl[i]) += sd[disk][srnr].pf;
#endif
/* Don't need that anymore, but it would be good to have) */
/* forget((void **) &sd[disk][srnr].pl); */
/* Add to number of points contributing to flux */
/* fluxpoints[disk] = */
sd[disk][srnr].fluxpoints = (sd[disk][srnr].npos-sd[disk][srnr].nneg)/sd[disk][srnr].nsubcl;
/* Return number of pointsources */
return sd[disk][srnr].allnpoints = (sd[disk][srnr].npos+sd[disk][srnr].nneg)/sd[disk][srnr].nsubcl;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Grids a point to a pointsource list */
#ifdef PBCORR
static int srput_norm(void (*corr_pbcfac)(struct srd **sd, int disk, int srnr, long grid), struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk)
#else
static int srput_norm(struct srd **sd, float *modpar, int nr, double *cflux, double radsep, int srnr, long *fluxpoints, int disk)
#endif
{
long i;
/****************/
/****************/
/* int obsint = 1; */
/* char obsmes[81]; */
/****************/
/******/
/******/
/* if (srnr == 0) { */
/* sprintf(obsmes, "ya got here: srput_norm disk: %i n: %i", disk, (int) sd[disk][srnr].n); */
/* anyout_tir(&obsint, obsmes); */
/* } */
/******/
/* What was the pointsource flux, note that this is done now in parallel (danger?) */
#ifdef PBCORR
for (i = 0; i < sd[disk][srnr].n; ++i)
corr_pbcfac(sd, disk, srnr, i);
#else
for (i = 0; i < sd[disk][srnr].n; ++i)
*(sd[disk][srnr].pl[i]) += sd[disk][srnr].pf;
#endif
/* Don't need that anymore, but it would be good to have) */
/* forget((void **) &sd[disk][srnr].pl); */
/* fluxpoints[disk] */
sd[disk][srnr].fluxpoints = sd[disk][srnr].n*(sd[disk][srnr].pf>0?1:-1)/sd[disk][srnr].nsubcl;
/* Return number of pointsources */
return sd[disk][srnr].allnpoints = sd[disk][srnr].n/sd[disk][srnr].nsubcl;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static long srconst(hdrinf *hdr, ringparms *rpm, int srnr, long mode, int disk)
{
int i;
/* The next four variables were declared static before, but now we use parallel code, such that it might be a bad idea */
float az;
float cosaz; /* The cos of the az (memory wasting) */
float sinaz; /* The sin of the az (memory wasting) */
float pp[6]; /* Cartesian coordinates in phase-space, x,y,z,vx,vy,vz */
/* x: DEC, y: RA, z: LOS towards observer */
char mes[180];
int err = 4;
int signum;
long npoints, j;
int dummyint;
/* First check if we do anything but remembering */
if (rpm -> sd[disk][srnr].pl) {
/* remember((void **) &rpm -> sd[disk][srnr].pl); */
return rpm -> sd[disk][srnr].outpoints = rpm -> sd[disk][srnr].outn/rpm -> sd[disk][srnr].nsubcl;
}
/* Now we try to allocate */
if ((rpm -> sd[disk][srnr].n)){
if (!(rpm -> sd[disk][srnr].pl = (float **) malloc(rpm -> sd[disk][srnr].n*sizeof(float *)))) {
/* Catastrophy, simply stop */
sprintf(mes, "Too many pointsources, increase PFLUX");
error_tir(&err, mes);
}
#ifdef PBCORR
rpm -> alloc_pbcfac(rpm, srnr, disk);
#endif
}
/* If there's no pointsource we allocate nevertheless for the smallest thing possible */
else {
if (!(rpm -> sd[disk][srnr].pl = (float **) malloc(sizeof(float *)))) {
/* Catastrophy, simply stop */
sprintf(mes, "Too many pointsources, increase PFLUX");
error_tir(&err, mes);
}
#ifdef PBCORR
rpm -> alloc_pbcfac(rpm, srnr, disk);
#endif
/* Changed this, but not sure */
rpm -> sd[disk][srnr].outn = rpm -> sd[disk][srnr].nneg = rpm -> sd[disk][srnr].npos = 0;
return rpm -> sd[disk][srnr].outpoints = 0;
}
/* Initialise random generators */
rpm -> sd[disk][srnr].iseed2[1] = srnr+disk;
maths_rndmf_init(rpm -> sd[disk][srnr].iseed2, rpm -> sd[disk][srnr].permrandstr);
/* reset the zprof */
zprof(6, rpm -> sd[disk][srnr].permrandstr, &(rpm -> sd[disk][srnr].y2));
/* Do the same for variable functions */
(*(rpm -> inf_sdisv[disk] -> rndmf_init))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> rndmf_init))((void *) rpm, srnr, disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init0))((void *) rpm, srnr, 0,disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init1))((void *) rpm, srnr, 1,disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init2))((void *) rpm, srnr, 2,disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init3))((void *) rpm, srnr, 3,disk);
/* Reset the counters */
j = 0;
rpm -> sd[disk][srnr].outn = 0;
/* rpm -> sd[disk][srnr].outnpos = */
/* rpm -> sd[disk][srnr].outnneg = 0; */
npoints = rpm -> sd[disk][srnr].nharmnorm;
signum = rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*rpm -> nr+srnr] > 0?1:0;
while (j < npoints) {
/* Calculate azimuth sine and cosine, conventional */
(*(rpm -> inf_smiv[disk] -> getaz))((void *) rpm, &az, &sinaz, &cosaz, &signum, srnr, disk);
/* Check if the azimuth is ok */
/* rpm -> sd[disk][srnr].outofrange = 1; */
(*(rpm -> inf_aziv[disk] -> setoutrange))(&(rpm -> sd[disk][srnr].outofrange));
(*(rpm -> inf_aziv[disk] -> pr0))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 0);
(*(rpm -> inf_aziv[disk] -> pr1))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 1);
/* Put the point source where it belongs */
/* Put the point source where it belongs */
dummyint = (*(rpm -> inf_aziv[disk] -> srshape))(rpm, pp, sinaz, cosaz, srnr, rpm -> sd[disk][srnr].outofrange, disk);
/* (*(rpm -> inf_aziv[disk] -> srshape))((void *) rpm, pp, sinaz, cosaz, srnr, rpm -> sd[disk][srnr].outofrange, disk); */
/* srshape(rpm, pp, sinaz, cosaz, srnr); */
/* Add ring-dependent dispersion, if activated */
(*(rpm -> inf_sdisv[disk] -> pr))((void *) rpm, pp+5, &az, srnr, disk);
/* Grid the point sources */
#ifdef PBCORR
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> fill_pbcfac, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#else
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#endif
/* Correct for the number of point sources if necessary */
rpm -> inf_aziv[disk] -> corrp((void *) rpm, srnr, &(rpm -> sd[disk][srnr].outofrange), signum);
(*(rpm -> inf_sdisv[disk] -> repeater))((void *) rpm, pp, az, srnr, hdr, &j, signum, &npoints, disk);
if (dummyint)
rpm -> sd[disk][srnr].outn = rpm -> sd[disk][srnr].outn-rpm -> sd[disk][srnr].nsubcl;
}
/* This is a departure from the policy of doing the best to prevent
the program from slowing down when including new parameters,
albeit a small one */
for (i = 0; i < 4; ++i) {
if ((rpm -> sd[disk][srnr].ngaussian[i])) {
npoints = npoints + rpm -> sd[disk][srnr].ngaussian[i];
/* Determine point source flux */
signum = rpm -> modpar[((PRPARAMS+disk*NDPARAMS+PGA1A)+3*i)*rpm -> nr+srnr] > 0?1:0;
while (j < npoints) {
/* Calculate azimuth sine and cosine, Gaussian */
gau_getaz(rpm, (PRPARAMS+disk*NDPARAMS+PGA1P)+3*i, rpm -> sd[disk][srnr].grandstr[i], i, &az, &sinaz, &cosaz, srnr, disk);
/* Check if the azimuth is ok */
/* rpm -> sd[disk][srnr].outofrange = 0; */
(*(rpm -> inf_aziv[disk] -> setoutrange))(&(rpm -> sd[disk][srnr].outofrange));
(*(rpm -> inf_aziv[disk] -> pr0))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 0);
(*(rpm -> inf_aziv[disk] -> pr1))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 1);
/* Put the point source where it belongs */
dummyint = (*(rpm -> inf_aziv[disk] -> srshape))(rpm, pp, sinaz, cosaz, srnr, rpm -> sd[disk][srnr].outofrange, disk);
/* srshape(rpm, pp, sinaz, cosaz, srnr); */
/* Add ring-dependent dispersion, if activated (why here and not in srshape?) */
(*(rpm -> inf_sdisv[disk] -> pr))((void *) rpm, pp+5, &az, srnr, disk);
#ifdef PBCORR
/* Grid the point sources */
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> fill_pbcfac, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#else
/* Grid the point sources */
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#endif
/* Correct for the number of point sources if necessary */
(*(rpm -> inf_aziv[disk] -> corrp))((void *) rpm, srnr, &(rpm -> sd[disk][srnr].outofrange), signum);
(*(rpm -> inf_sdisv[disk] -> repeater))((void *) rpm, pp, az, srnr, hdr, &j, signum, &npoints, disk);
if (dummyint)
rpm -> sd[disk][srnr].outn = rpm -> sd[disk][srnr].outn-rpm -> sd[disk][srnr].nsubcl;
}
}
}
return rpm -> sd[disk][srnr].outpoints = rpm -> sd[disk][srnr].outn/rpm -> sd[disk][srnr].nsubcl;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static long srconstcool(hdrinf *hdr, ringparms *rpm, int srnr, long mode, int disk)
{
int i;
/* The next four variables were declared static before, but now we use parallel code, such that it might be a bad idea */
float az;
float cosaz; /* The cos of the az (memory wasting) */
float sinaz; /* The sin of the az (memory wasting) */
float pp[6]; /* Cartesian coordinates in phase-space, x,y,z,vx,vy,vz */
/* x: DEC, y: RA, z: LOS towards observer */
char mes[180];
int err = 4;
int signum;
long npoints, j;
int dummyint;
/* First check if we do anything but remembering */
/* if (rpm -> sd[disk][srnr].pl) { */
/* remember((void **) &rpm -> sd[disk][srnr].pl); */
/* return rpm -> sd[disk][srnr].outpoints = rpm -> sd[disk][srnr].outn/rpm -> sd[disk][srnr].nsubcl; */
/* } */
/* Now we try to allocate */
if ((rpm -> sd[disk][srnr].n)){
if (!(rpm -> sd[disk][srnr].pl = (float **) malloc(rpm -> sd[disk][srnr].n*sizeof(float *)))) {
/* Catastrophy, simply stop */
sprintf(mes, "Too many pointsources, increase PFLUX");
error_tir(&err, mes);
}
#ifdef PBCORR
rpm -> alloc_pbcfac(rpm, srnr, disk);
#endif
}
/* If there's no pointsource we allocate nevertheless for the smallest thing possible */
else {
if (!(rpm -> sd[disk][srnr].pl = (float **) malloc(sizeof(float *)))) {
/* Catastrophy, simply stop */
sprintf(mes, "Too many pointsources, increase PFLUX");
error_tir(&err, mes);
}
#ifdef PBCORR
rpm -> alloc_pbcfac(rpm, srnr, disk);
#endif
/* Changed this, but not sure */
rpm -> sd[disk][srnr].outn = rpm -> sd[disk][srnr].nneg = rpm -> sd[disk][srnr].npos = 0;
return rpm -> sd[disk][srnr].outpoints = 0;
}
/* Initialise random generators */
rpm -> sd[disk][srnr].iseed2[1] = srnr+disk;
maths_rndmf_init(rpm -> sd[disk][srnr].iseed2, rpm -> sd[disk][srnr].permrandstr);
/* reset the zprof */
zprof(6, rpm -> sd[disk][srnr].permrandstr, &(rpm -> sd[disk][srnr].y2));
/* Do the same for variable functions */
(*(rpm -> inf_sdisv[disk] -> rndmf_init))((void *) rpm, srnr, disk);
(*(rpm -> inf_smiv[disk] -> rndmf_init))((void *) rpm, srnr, disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init0))((void *) rpm, srnr, 0,disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init1))((void *) rpm, srnr, 1,disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init2))((void *) rpm, srnr, 2,disk);
(*(rpm -> inf_gauv[disk] -> rndmf_init3))((void *) rpm, srnr, 3,disk);
/* Reset the counters */
j = 0;
rpm -> sd[disk][srnr].outn = 0;
/* rpm -> sd[disk][srnr].outnpos = */
/* rpm -> sd[disk][srnr].outnneg = 0; */
npoints = rpm -> sd[disk][srnr].nharmnorm;
signum = rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*rpm -> nr+srnr] > 0?1:0;
while (j < npoints) {
/* Calculate azimuth sine and cosine, conventional */
(*(rpm -> inf_smiv[disk] -> getaz))((void *) rpm, &az, &sinaz, &cosaz, &signum, srnr, disk);
/* Check if the azimuth is ok */
/* rpm -> sd[disk][srnr].outofrange = 1; */
(*(rpm -> inf_aziv[disk] -> setoutrange))(&(rpm -> sd[disk][srnr].outofrange));
(*(rpm -> inf_aziv[disk] -> pr0))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 0);
(*(rpm -> inf_aziv[disk] -> pr1))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 1);
/* Put the point source where it belongs */
/* Put the point source where it belongs */
dummyint = (*(rpm -> inf_aziv[disk] -> srshape))(rpm, pp, sinaz, cosaz, srnr, rpm -> sd[disk][srnr].outofrange, disk);
/* (*(rpm -> inf_aziv[disk] -> srshape))((void *) rpm, pp, sinaz, cosaz, srnr, rpm -> sd[disk][srnr].outofrange, disk); */
/* srshape(rpm, pp, sinaz, cosaz, srnr); */
/* Add ring-dependent dispersion, if activated */
/* (*(rpm -> inf_sdisv[disk] -> pr))((void *) rpm, pp+5, &az, srnr, disk); */
/* Grid the point sources */
#ifdef PBCORR
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> fill_pbcfac, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#else
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#endif
/* Correct for the number of point sources if necessary */
rpm -> inf_aziv[disk] -> corrp((void *) rpm, srnr, &(rpm -> sd[disk][srnr].outofrange), signum);
(*(rpm -> inf_sdisv[disk] -> repeater))((void *) rpm, pp, az, srnr, hdr, &j, signum, &npoints, disk);
if (dummyint)
rpm -> sd[disk][srnr].outn = rpm -> sd[disk][srnr].outn-rpm -> sd[disk][srnr].nsubcl;
}
/* This is a departure from the policy of doing the best to prevent
the program from slowing down when including new parameters,
albeit a small one */
for (i = 0; i < 4; ++i) {
if ((rpm -> sd[disk][srnr].ngaussian[i])) {
npoints = npoints + rpm -> sd[disk][srnr].ngaussian[i];
/* Determine point source flux */
signum = rpm -> modpar[((PRPARAMS+disk*NDPARAMS+PGA1A)+3*i)*rpm -> nr+srnr] > 0?1:0;
while (j < npoints) {
/* Calculate azimuth sine and cosine, Gaussian */
gau_getaz(rpm, (PRPARAMS+disk*NDPARAMS+PGA1P)+3*i, rpm -> sd[disk][srnr].grandstr[i], i, &az, &sinaz, &cosaz, srnr, disk);
/* Check if the azimuth is ok */
/* rpm -> sd[disk][srnr].outofrange = 0; */
(*(rpm -> inf_aziv[disk] -> setoutrange))(&(rpm -> sd[disk][srnr].outofrange));
(*(rpm -> inf_aziv[disk] -> pr0))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 0);
(*(rpm -> inf_aziv[disk] -> pr1))(&az, rpm -> sd[disk][srnr].ranges, &(rpm -> sd[disk][srnr].outofrange), 1);
/* Put the point source where it belongs */
dummyint = (*(rpm -> inf_aziv[disk] -> srshape))(rpm, pp, sinaz, cosaz, srnr, rpm -> sd[disk][srnr].outofrange, disk);
/* srshape(rpm, pp, sinaz, cosaz, srnr); */
/* Add ring-dependent dispersion, if activated (why here and not in srshape?) */
/* (*(rpm -> inf_sdisv[disk] -> pr))((void *) rpm, pp+5, &az, srnr, disk); */
#ifdef PBCORR
/* Grid the point sources */
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> fill_pbcfac, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#else
/* Grid the point sources */
(*(rpm -> sd[disk][srnr].gridpoint))(hdr, rpm -> modpar, rpm -> nr, rpm -> sd, srnr, &j, pp, signum, &npoints, disk);
#endif
/* Correct for the number of point sources if necessary */
(*(rpm -> inf_aziv[disk] -> corrp))((void *) rpm, srnr, &(rpm -> sd[disk][srnr].outofrange), signum);
(*(rpm -> inf_sdisv[disk] -> repeater))((void *) rpm, pp, az, srnr, hdr, &j, signum, &npoints, disk);
if (dummyint)
rpm -> sd[disk][srnr].outn = rpm -> sd[disk][srnr].outn-rpm -> sd[disk][srnr].nsubcl;
}
}
}
return rpm -> sd[disk][srnr].outpoints = rpm -> sd[disk][srnr].outn/rpm -> sd[disk][srnr].nsubcl;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static void srshape(ringparms *rpm, float *pp, float sinaz, float cosaz, int srnr, int disk)
{
float r;
float pp2[6];
/* The probability for the radius is weighted by r, and this is no approximation, hence a speed brake, should be removed at some point */
r = sqrtf((rpm -> modpar[PRADI*rpm -> nr+srnr]-0.5*rpm -> radsep)*(rpm -> modpar[PRADI*rpm -> nr+srnr]-0.5*rpm -> radsep)+2*rpm -> radsep*rpm -> modpar[PRADI*rpm -> nr+srnr]*maths_rndmf(rpm -> sd[disk][srnr].permrandstr));
/* Calculate the coordinates of the point source before rotation */
pp[0] = cosaz*r;
pp[1] = sinaz*r;
pp[2] = zprof(rpm -> ltype[disk], rpm -> sd[disk][srnr].permrandstr, &(rpm -> sd[disk][srnr].y2))*rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PZ0)*rpm -> nr+srnr];
pp[4] = cosaz*rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PVROT)*rpm -> nr+srnr];
/* Here comes the harmonic velocity terms */
(*(rpm -> inf_ro1v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ro2v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ro3v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ro4v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ro1v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ro2v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ro3v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ro4v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
/* vertical gradient in rotation velocity */
(*(rpm -> inf_dvrov[disk] -> pr)) ((void *) rpm, pp, srnr, sinaz, cosaz, disk);
/* Radial velocity term */
(*(rpm -> inf_vradv[disk] -> pr)) ((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
/* Here comes the harmonic velocity terms */
(*(rpm -> inf_ra1v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ra2v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ra3v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ra4v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ra1v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ra2v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ra3v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ra4v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk);
/* vertical gradient in radial velocity */
(*(rpm -> inf_dvrav[disk] -> pr)) ((void *) rpm, pp, srnr, sinaz, cosaz, disk);
pp[5] = 0.0;
/* Vertical velocity term */
(*(rpm -> inf_vverv[disk] -> pr)) ((void *) rpm, pp, srnr, disk);
/* vertical gradient in vertical velocity */
(*(rpm -> inf_dvvev[disk] -> pr)) ((void *) rpm, pp, srnr, disk);
/* We do the warp harmonics here */
(*(rpm -> inf_wm1v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm2v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm3v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm4v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm1v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm2v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm3v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm4v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm0v[disk] -> pr)) ((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
/* Now rotate about the x-axis by i */
pp2[0] = pp[0];
pp2[1] = pp[1]*rpm -> sd[disk][srnr].cosi-pp[2]*rpm -> sd[disk][srnr].sini;
/* Now we shift */
(*(rpm -> inf_lc0v[disk] -> pr))((void *) rpm, pp2+0, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ls0v[disk] -> pr))((void *) rpm, pp2+1, srnr, sinaz, cosaz, disk);
/* pp2[2] = pp[1]*rpm -> sd[disk][srnr].sini+pp[2]*rpm -> sd[disk][srnr].cosi; */
/* pp2[3] = pp[3]; */
/* pp2[4] = pp[4]*rpm -> sd[disk][srnr].cosi-pp[5]*rpm -> sd[disk][srnr].sini; */
/* pp2[5] = pp[4]*rpm -> sd[disk][srnr].sini+pp[5]*rpm -> sd[disk][srnr].cosi; */
pp2[5] = pp[4]*rpm -> sd[disk][srnr].sini;
/* But if we did a vertical velocity component */
(*(rpm -> inf_vverv[disk] -> pr_rota)) ((void *) rpm, pp+5, pp2+5, srnr, disk);
/* Here comes the harmonic velocity terms */
(*(rpm -> inf_vm1v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm2v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm3v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm4v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm1v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm2v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm3v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm4v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_vm0v[disk] -> pr))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk);
/* Now rotate about the z-axis by pa */
/* pp[0] = pp2[0]*rpm -> sd[disk][srnr].cosp-pp2[1]*rpm -> sd[disk][srnr].sinp; */
/* pp[1] = pp2[0]*rpm -> sd[disk][srnr].sinp+pp2[1]*rpm -> sd[disk][srnr].cosp; */
/* pp[2] = pp2[2]; */
/* pp[3] = pp2[3]*rpm -> sd[disk][srnr].cosp-pp2[4]*rpm -> sd[disk][srnr].sinp; */
/* pp[4] = pp2[3]*rpm -> sd[disk][srnr].sinp+pp2[4]*rpm -> sd[disk][srnr].cosp; */
/* pp[5] = pp2[5]; */
/* Here's the shortcut version */
pp[0] = pp2[0]*rpm -> sd[disk][srnr].cosp-pp2[1]*rpm -> sd[disk][srnr].sinp;
pp[1] = pp2[0]*rpm -> sd[disk][srnr].sinp+pp2[1]*rpm -> sd[disk][srnr].cosp;
pp[5] = pp2[5];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static void srshapecool(ringparms *rpm, float *pp, float sinaz, float cosaz, int srnr, int disk)
{
float r;
float pp2[6];
/* The probability for the radius is weighted by r, and this is no approximation, hence a speed brake, should be removed at some point */
r = sqrtf((rpm -> modpar[PRADI*rpm -> nr+srnr]-0.5*rpm -> radsep)*(rpm -> modpar[PRADI*rpm -> nr+srnr]-0.5*rpm -> radsep)+2*rpm -> radsep*rpm -> modpar[PRADI*rpm -> nr+srnr]*maths_rndmf(rpm -> sd[disk][srnr].permrandstr));
/* Calculate the coordinates of the point source before rotation */
pp[0] = cosaz*r;
pp[1] = sinaz*r;
pp[2] = zprof(rpm -> ltype[disk], rpm -> sd[disk][srnr].permrandstr, &(rpm -> sd[disk][srnr].y2))*rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PZ0)*rpm -> nr+srnr];
/* pp[4] = cosaz*rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PVROT)*rpm -> nr+srnr]; */
/* Here comes the harmonic velocity terms */
/* (*(rpm -> inf_ro1v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ro2v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ro3v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ro4v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ro1v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ro2v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ro3v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ro4v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* vertical gradient in rotation velocity */
/* (*(rpm -> inf_dvrov[disk] -> pr)) ((void *) rpm, pp, srnr, sinaz, cosaz, disk); */
/* Radial velocity term */
/* (*(rpm -> inf_vradv[disk] -> pr)) ((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* Here comes the harmonic velocity terms */
/* (*(rpm -> inf_ra1v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ra2v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ra3v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ra4v[disk] -> prs))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ra1v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ra2v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ra3v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_ra4v[disk] -> prc))((void *) rpm, pp+4, srnr, sinaz, cosaz, disk); */
/* vertical gradient in radial velocity */
/* (*(rpm -> inf_dvrav[disk] -> pr)) ((void *) rpm, pp, srnr, sinaz, cosaz, disk); */
/* pp[5] = 0.0; */
/* Vertical velocity term */
/* (*(rpm -> inf_vverv[disk] -> pr)) ((void *) rpm, pp, srnr, disk); */
/* vertical gradient in vertical velocity */
/* (*(rpm -> inf_dvvev[disk] -> pr)) ((void *) rpm, pp, srnr, disk); */
/* We do the warp harmonics here */
(*(rpm -> inf_wm1v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm2v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm3v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm4v[disk] -> prs))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm1v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm2v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm3v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm4v[disk] -> prc))((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_wm0v[disk] -> pr)) ((void *) rpm, pp+2, srnr, sinaz, cosaz, disk);
/* Now rotate about the x-axis by i */
pp2[0] = pp[0];
pp2[1] = pp[1]*rpm -> sd[disk][srnr].cosi-pp[2]*rpm -> sd[disk][srnr].sini;
pp2[2] = pp[1]*rpm -> sd[disk][srnr].sini+pp[2]*rpm -> sd[disk][srnr].cosi;
/* Now we shift */
(*(rpm -> inf_lc0v[disk] -> pr))((void *) rpm, pp2+0, srnr, sinaz, cosaz, disk);
(*(rpm -> inf_ls0v[disk] -> pr))((void *) rpm, pp2+1, srnr, sinaz, cosaz, disk);
/* pp2[2] = pp[1]*rpm -> sd[disk][srnr].sini+pp[2]*rpm -> sd[disk][srnr].cosi; */
/* pp2[3] = pp[3]; */
/* pp2[4] = pp[4]*rpm -> sd[disk][srnr].cosi-pp[5]*rpm -> sd[disk][srnr].sini; */
/* pp2[5] = pp[4]*rpm -> sd[disk][srnr].sini+pp[5]*rpm -> sd[disk][srnr].cosi; */
/* pp2[5] = pp[4]*rpm -> sd[disk][srnr].sini; */
/* But if we did a vertical velocity component */
/* (*(rpm -> inf_vverv[disk] -> pr_rota)) ((void *) rpm, pp+5, pp2+5, srnr, disk); */
/* Here comes the harmonic velocity terms */
/* (*(rpm -> inf_vm1v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm2v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm3v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm4v[disk] -> prs))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm1v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm2v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm3v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm4v[disk] -> prc))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* (*(rpm -> inf_vm0v[disk] -> pr))((void *) rpm, pp2+5, srnr, sinaz, cosaz, disk); */
/* Now rotate about the z-axis by pa */
/* pp[0] = pp2[0]*rpm -> sd[disk][srnr].cosp-pp2[1]*rpm -> sd[disk][srnr].sinp; */
/* pp[1] = pp2[0]*rpm -> sd[disk][srnr].sinp+pp2[1]*rpm -> sd[disk][srnr].cosp; */
/* pp[2] = pp2[2]; */
/* pp[3] = pp2[3]*rpm -> sd[disk][srnr].cosp-pp2[4]*rpm -> sd[disk][srnr].sinp; */
/* pp[4] = pp2[3]*rpm -> sd[disk][srnr].sinp+pp2[4]*rpm -> sd[disk][srnr].cosp; */
/* pp[5] = pp2[5]; */
/* Here's the shortcut version */
pp[0] = pp2[0]*rpm -> sd[disk][srnr].cosp-pp2[1]*rpm -> sd[disk][srnr].sinp;
pp[1] = pp2[0]*rpm -> sd[disk][srnr].sinp+pp2[1]*rpm -> sd[disk][srnr].cosp;
pp[2] = pp2[2];
/* pp[5] = pp2[5]; */
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Help function to interpover: Check if the modpar array in the range
of a ring has to be changed */
static int chkchangep(varlel *varele, int fitmode, int parnr, int nur)
{
int i, param;
/* int k; */
/* If fitmode is Golden Section, we check only the actual varele element */
if ((fitmode == GOLDEN_SECTION)) {
for (i = 0; i < varele -> nelem; ++i) {
/* If the ring itself or the ting before has been changed, we return */
if (parnr == varele -> elements[i])
return 1;
/* Don't know whether the second logical is a good idea */
/* if ((parnr == param+1) && ((param+1)%nur)) */
/* return 1; */
/* for (j = 0; j < index -> nuel; ++j) { */
/* if (index -> inpal[j] == varele -> elements[i] || index -> inpah[j] == varele -> elements[i]) { */
/* if (parnr == (param = index -> ipa[j])) { */
/* return 1; */
/* } */
/* if ((parnr == param+1) && ((param+1)%nur)) { */
/* return 1; */
/* } */
/* } */
/* } */
}
}
/* Fitmode is Metropolis, we check the whole list */
else {
/* k = 0; */
while ((varele)) {
/* fprintf(stderr,"This is the number: %i\n", k); */
/* if (k == 2) { */
/* if (parnr == 131) */
/* printf("Should get there... %i ", k); */
/* } */
if ((varele -> indicator)) {
/* if (k == 2) { */
/* if (parnr == 131) */
/* printf("got here! "); */
/* } */
for (i = 0; i < varele -> nelem; ++i) {
/* If the ring itself or the ting before has been changed, we return */
if (parnr == (param = varele -> elements[i])) {
/* if (parnr == 131) */
/* printf("ding... "); */
return 1;
}
/* param = varele -> elements[i]; */
/* if ((parnr == param+1) && ((param+1)%nur)) { */
/* if (parnr == 131) */
/* printf("dong... "); */
/* return 1; */
/* } */
/* for (j = 0; j < index -> nuel; ++j) { */
/* if (index -> inpal[j] == varele -> elements[i] || index -> inpah[j] == varele -> elements[i]) { */
/* if (parnr == (param = index -> ipa[j])) { */
/* return 1; */
/* } */
/* if ((parnr == param+1) && ((param+1)%nur)) { */
/* return 1; */
/* } */
/* } */
/* } */
}
}
varele = varele -> next;
/* ++k; */
}
}
/* The parameter is not in there */
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Takes the parameter list and changes the parameters on the index */
static int changedependent(ringparms *rpm, double *par, decomp_inlist *index, int *chapar)
{
int i,j,k,counts;
int nactive; /* number of active points (not indexed) */
gsl_interp *gsl_interpv = NULL; /* interpolation function */
gsl_interp_accel *gsl_interp_accelv = NULL; /* interpolation function accelerator */
double dummy;
/* fprintf(stderr,"got here\n"); */
if (!(index -> nuel))
return 0;
/* index is strictly sorted */
counts = 0;
/* BUGFIX: this outer loop is required to catch a situation where a parameter is interpolated over but does not belong to a group which is fitted */
while (counts < index -> nuel) {
/* loop over all parameters except the radii */
for (j = NSSDPARAMS; j < NSSDPARAMS+rpm -> ndisks*NDPARAMS; ++j) {
nactive = 0;
/* Check if any of the parameters in that parameter group has changed */
for (i = 0; i < rpm -> nur; ++i) {
if (chapar[j*rpm->nur+i]) {
break;
}
}
/* Only if there was a change, we need to interpolate in that group */
if (i < rpm -> nur) {
for (i = 0; i < rpm -> nur; ++i) {
rpm -> actindar[i] = j*rpm -> nur + i;
if (index -> ipa[counts] == rpm -> actindar[i]) {
rpm -> actarray[i] = 0;
++counts;
}
else {
rpm -> actarray[i] = 1;
++nactive;
}
}
/* fprintf(stderr,"got here2\n"); */
/* Now evaluate a few situations */
/* If there has been no dependent parameter, we do not need to do anything */
if (nactive != rpm -> nur) {
/* Only one active parameter for all */
if (nactive == 1) {
for (i = 0; i < rpm -> nur; ++i) {
par[j*rpm -> nur + i] = par[index -> inpal[counts-1]];
chapar[j*rpm -> nur + i] = 1;
}
}
/* Otherwise interpolation */
else {
i = 0;
while (!(rpm -> actarray[i]))
++i;
if (i) {
rpm -> actarray[0] = 1;
par[j*rpm -> nur] = par[rpm -> actindar[i]];
chapar[j*rpm -> nur] = 1;
}
i = rpm -> nur-1;
while (!(rpm -> actarray[i]))
--i;
if (i != (rpm -> nur-1)) {
rpm -> actarray[rpm -> nur-1] = 1;
par[(j+1)*rpm -> nur-1] = par[rpm -> actindar[i]];
chapar[(j+1)*rpm -> nur-1] = 1;
}
/* Now fill the arrays to be passed to the interpolator */
k = 0;
for (i = 0; i < rpm -> nur; ++i) {
if (rpm -> actarray[i]) {
rpm -> radar[k] = par[PRADI*rpm -> nur+i];
rpm -> interar[k] = par[rpm -> actindar[i]];
++k;
}
}
/* Interpolate: use the appropriate mode, same as defined in rpm -> smothcar (user input indy) unless number of available points is 2, which entails linear */
/* This we need in any case */
if (!(gsl_interp_accelv = gsl_interp_accel_alloc()))
goto error;
/* Linear */
if ((k < 3) || rpm -> smothindcar[j-NPARAMS+NDPARAMS] == INTERP_LINEAR ) {
if (!(gsl_interpv = gsl_interp_alloc (gsl_interp_linear, k)))
goto error;
}
/* Spline */
else if (k < 5 || rpm -> smothindcar[j-NPARAMS+NDPARAMS] == INTERP_CSPLINE) {
if (!(gsl_interpv = gsl_interp_alloc (gsl_interp_cspline, k)))
goto error;
}
/* Akima */
else if (rpm -> smothindcar[j-NPARAMS+NDPARAMS] == INTERP_AKIMA) {
if (!(gsl_interpv = gsl_interp_alloc (gsl_interp_akima, k)))
goto error;
}
/* Something's wrong */
else
goto error;
gsl_interp_init (gsl_interpv, rpm -> radar, rpm -> interar, k);
/* Now interpolate where required */
for (i = 0; i < rpm -> nur; ++i) {
/* fprintf(stderr,"got here number: %i %i\n", i, rpm -> actarray[i]); */
if (!(rpm -> actarray[i])) {
dummy = par[rpm -> actindar[i]];
par[rpm -> actindar[i]] = gsl_interp_eval(gsl_interpv, rpm -> radar, rpm -> interar, par[PRADI*rpm -> nur+i], gsl_interp_accelv);
/* If there was a change, we note it down */
if (par[rpm -> actindar[i]] != dummy) {
/* fprintf(stderr,"Found this to have changed: %i\n", i); */
rpm -> chapar[rpm -> actindar[i]] = 1;
}
}
}
}
gsl_interp_free(gsl_interpv);
gsl_interp_accel_free(gsl_interp_accelv);
}
if (counts == index -> nuel)
break;
}
}
++counts;
}
/*
#ifdef OPENMPTIR
#pragma omp parallel for schedule(dynamic)
#endif
for (i = 0; i < index -> nuel; ++i) { */
/* First check if the upper and the lower index are identical */
/* if (index -> inpal[i] == index -> inpah[i]) {
if (index -> ipa[i] != index -> inpal[i]) {
par[index -> ipa[i]] = par[index -> inpal[i]];
}
}
else {
*/
/* And interpolate the parameter */
/* par[index -> ipa[i]] = par[index -> inpal[i]]+(par[PRADI*rpm -> nur+index -> ripa[i]]-par[PRADI*rpm -> nur+index -> rinpal[i]])*(par[index -> inpah[i]]-par[index -> inpal[i]])/(par[PRADI*rpm -> nur+index -> rinpah[i]] - par[PRADI*rpm -> nur+index -> rinpal[i]]);
}
} */
return index -> nuel;
error:
if (gsl_interpv)
gsl_interp_free(gsl_interpv);
if (gsl_interp_accelv)
gsl_interp_accel_free(gsl_interp_accelv);
return -1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Core to construct a pointsource cube from a parameter list */
static int galmod(hdrinf *hdr, ringparms *rpm, int fitmode, varlel *varele, decomp_inlist *index, long *fluxpoints, int *allnpoints)
{ int i;
int disk, allnpoint = 0;
interpover(rpm, rpm -> radsep, fitmode, varele, index);
/* Initialise the model array */
/* for (i = 0; i < hdr -> bcsize1*hdr -> bsize2*hdr -> nsubs; ++i) */
#ifdef OPENMPTIR
#pragma omp parallel for schedule(dynamic)
#endif
for (i = 0; i < hdr -> nprof*hdr -> nsubs; ++i)
hdr -> modelc -> points[i] = 0;
/* Initialise the chisquare */
/* hdr -> chi2 = 0; */
rpm -> outpoints = 0;
for (disk = 0; disk < rpm -> ndisks; ++disk) {
allnpoints[disk] = 0;
fluxpoints[disk] = 0;
/* Do all the loops */
#ifdef OPENMPTIR
#pragma omp parallel for schedule(dynamic)
#endif
for (i = 0; i < rpm -> nr; ++i) {
/* rpm -> outpoints += */
srconst(hdr, rpm, i, 0, disk);
}
/* non-parallel bookkeeping */
for (i = 0; i < rpm -> nr; ++i) {
/* now create the clouds and grid them, seems to go well, although there is an additional component there */
/* allnpoints[disk] += */
#ifdef PBCORR
(*(rpm -> sd[disk][i].srput))(rpm -> corr_pbcfac, rpm -> sd, rpm -> modpar, rpm -> nr, rpm -> cflux, rpm -> radsep, i, fluxpoints, disk);
#else
(*(rpm -> sd[disk][i].srput))(rpm -> sd, rpm -> modpar, rpm -> nr, rpm -> cflux, rpm -> radsep, i, fluxpoints, disk);
#endif
/* this should be correct */
rpm -> outpoints += rpm -> sd[disk][i].outpoints;
/* this might not be correct */
allnpoints[disk] += rpm -> sd[disk][i].allnpoints;
fluxpoints[disk] += rpm -> sd[disk][i].fluxpoints;
}
}
/* We return the number of clouds */
for (disk = 0; disk < rpm -> ndisks; ++disk)
allnpoint += allnpoints[disk];
return allnpoint;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Core to construct a pointsource cube from a parameter list */
static int galmodcool(hdrinf *hdr, ringparms *rpm, int fitmode, varlel *varele, decomp_inlist *index, long *fluxpoints, int *allnpoints)
{ int i;
int disk, allnpoint = 0;
int numpixs;
interpover(rpm, rpm -> radsep, fitmode, varele, index);
/* Initialise the model array */
/* for (i = 0; i < hdr -> bcsize1*hdr -> bsize2*hdr -> nsubs; ++i) */
numpixs = hdr -> coolcube -> size_x*hdr -> coolcube -> size_y*hdr -> coolcube -> size_v;
#ifdef OPENMPTIR
#pragma omp parallel for schedule(dynamic)
#endif
for (i = 0; i < numpixs; ++i)
hdr -> coolcube -> points[i] = 0;
/* Initialise the chisquare */
/* hdr -> chi2 = 0; */
rpm -> outpoints = 0;
for (disk = 0; disk < rpm -> ndisks; ++disk) {
allnpoints[disk] = 0;
fluxpoints[disk] = 0;
/* Make sure that the correct function is linked for srconst */
if (rpm -> inf_aziv[disk] -> srshape == srshape_azi_act) {
rpm -> inf_aziv[disk] -> srshape = srshape_azi_actcool;
}
else {
rpm -> inf_aziv[disk] -> srshape = srshape_azi_pascool;
}
/* Link the correct gridpoint function */
if (rpm -> inf_sdisv[disk] -> repeater == sdis_repeater_act) {
rpm -> inf_sdisv[disk] -> repeater = sdis_repeater_actcool;
}
else {
rpm -> inf_sdisv[disk] -> repeater = sdis_repeater_pascool;
}
for (i = 0; i < rpm -> nr; ++i) {
if (rpm -> sd[disk][i].gridpoint == gridpoint_norm) {
rpm -> sd[disk][i].gridpoint = gridpoint_normcool;
}
else {
rpm -> sd[disk][i].gridpoint = gridpoint_mixedcool;
}
}
/* Do all the loops */
#ifdef OPENMPTIR
#pragma omp parallel for schedule(dynamic)
#endif
for (i = 0; i < rpm -> nr; ++i) {
/* rpm -> outpoints += */
srconstcool(hdr, rpm, i, 0, disk);
}
/* non-parallel bookkeeping */
for (i = 0; i < rpm -> nr; ++i) {
/* now create the clouds and grid them, seems to go well, although there is an additional component there */
/* allnpoints[disk] += */
#ifdef PBCORR
(*(rpm -> sd[disk][i].srput))(rpm -> corr_pbcfac, rpm -> sd, rpm -> modpar, rpm -> nr, rpm -> cflux, rpm -> radsep, i, fluxpoints, disk);
#else
(*(rpm -> sd[disk][i].srput))(rpm -> sd, rpm -> modpar, rpm -> nr, rpm -> cflux, rpm -> radsep, i, fluxpoints, disk);
#endif
/* this should be correct */
rpm -> outpoints += rpm -> sd[disk][i].outpoints;
/* this might not be correct */
allnpoints[disk] += rpm -> sd[disk][i].allnpoints;
fluxpoints[disk] += rpm -> sd[disk][i].fluxpoints;
}
/* Make sure that the correct function is linked for srconst at the end*/
if (rpm -> inf_aziv[disk] -> srshape == srshape_azi_actcool) {
rpm -> inf_aziv[disk] -> srshape = srshape_azi_act;
}
else {
rpm -> inf_aziv[disk] -> srshape = srshape_azi_pas;
}
if (rpm -> inf_sdisv[disk] -> repeater == sdis_repeater_actcool) {
rpm -> inf_sdisv[disk] -> repeater = sdis_repeater_act;
}
else {
rpm -> inf_sdisv[disk] -> repeater = sdis_repeater_pas;
}
/* Link the correct gridpoint function back */
for (i = 0; i < rpm -> nr; ++i) {
if (rpm -> sd[disk][i].gridpoint == gridpoint_normcool) {
rpm -> sd[disk][i].gridpoint = gridpoint_norm;
}
else {
rpm -> sd[disk][i].gridpoint = gridpoint_mixed;
}
}
}
/* We return the number of clouds */
for (disk = 0; disk < rpm -> ndisks; ++disk)
allnpoint += allnpoints[disk];
return allnpoint;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Changes the parameters in par according to parms */
static int chprm_gen(double *parms, varlel *varylist, double *newpar)
{
int i,j = 0;
int outofrange = 0;
double oldzero = 0.0;
/* As long as there is any element of varylist we continue */
while ((varylist)) {
varylist -> indicator = 0;
oldzero = newpar[varylist -> elements[0]];
if (!(parms[j] == oldzero)) {
varylist -> indicator = 1;
/* Every adressant of elements will be changed by the same amount */
for (i = 0; i < varylist -> nelem; ++i) {
newpar[varylist -> elements[i]] = newpar[varylist -> elements[i]]-oldzero+parms[j];
/* And it will be checked whether on of them is out of range */
if (maths_checkinbetw(varylist -> parmax, varylist -> parmin, newpar[varylist -> elements[i]])) {
++outofrange;
}
}
}
++j;
varylist = varylist -> next;
}
return outofrange;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Writes the information contained in rpm -> par to the output */
static void writeoutput(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, double dof, int modcount, double rchisq)
{
int i;
/* char mes[80]; */
/* int dev = 0; */
if (fit -> fitmode > GOLDEN_SECTION)
writeoutarray(log, hdr, rpm, rpm -> par, accept, hdr -> oldchi2, modcount, dof, rchisq);
else
writeoutarray(log, hdr, rpm, rpm -> oldpar, accept, hdr -> oldchi2, modcount, dof, -1.0);
if ((log -> tstream)) {
fprintf(log -> tstream, "%7i ", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+LOOPNR_TABNR]);
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur + NSPARAMS; ++i) {
fprintf(log -> tstream, "%12.9e ", log -> outarray[i]);
}
fprintf(log -> tstream, "%.16e ", log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+CHISQ_TABNR]);
fprintf(log -> tstream, "%.16e ", log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+RCHISQ_TABNR]);
fprintf(log -> tstream, "%9i\n", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+ACCEPT_TABNR]);
}
if (!(log -> logpres)) {
ftstab_appendrow_(log -> outarray+(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+CHISQ_TABNR);
}
tir_put_register(log, rpm, log -> outarray);
/* Comment on it */
/* dev = 0; */
/* if (fit -> fitmode == METROPOLIS) */
/* sprintf(mes, "Model %i, chisquare %E, relative probability: %E", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+LOOPNR_TABNR], hdr -> chi2, proba); */
/* else if (fit -> fitmode == GOLDEN_SECTION) */
/* sprintf(mes, "Loop %i, %i iterations since start, chisquare %E", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+LOOPNR_TABNR], (int) proba, hdr -> oldchi2); */
/* anyout_tir(&dev, mes); */
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Writes the information contained in rpm -> par to the output */
static void writeoutputread(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit, char accept, double dof, int modcount, double rchisq)
{
int i;
/* char mes[80]; */
/* int dev = 0; */
if (fit -> fitmode > GOLDEN_SECTION)
writeoutarray(log, hdr, rpm, rpm -> par, accept, hdr -> oldchi2, modcount, dof, rchisq);
else
writeoutarray(log, hdr, rpm, rpm -> oldpar, accept, hdr -> oldchi2, modcount, dof, -1.0);
if ((log -> tstream)) {
fprintf(log -> tstream, "%7i ", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+LOOPNR_TABNR]);
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur + NSPARAMS; ++i) {
fprintf(log -> tstream, "%12.9e ", log -> outarray[i]);
}
fprintf(log -> tstream, "%.16e ", log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+CHISQ_TABNR]);
fprintf(log -> tstream, "%.16e ", log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+RCHISQ_TABNR]);
fprintf(log -> tstream, "%9i\n", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+ACCEPT_TABNR]);
}
tir_put_register(log, rpm, log -> outarray);
/* Comment on it */
/* dev = 0; */
/* if (fit -> fitmode == METROPOLIS) */
/* sprintf(mes, "Model %i, chisquare %E, relative probability: %E", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+LOOPNR_TABNR], hdr -> chi2, proba); */
/* else if (fit -> fitmode == GOLDEN_SECTION) */
/* sprintf(mes, "Loop %i, %i iterations since start, chisquare %E", (int) log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+LOOPNR_TABNR], (int) proba, hdr -> oldchi2); */
/* anyout_tir(&dev, mes); */
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Writes the information contained in rpm -> par to the output array of rpm */
void writeoutarray(loginf *log, hdrinf *hdr, ringparms *rpm, double *par, char accept, double chisquare, int modcount, double dof, double chisquare_red)
{
int i;
double globin[3];
double globout[3];
int disk;
int condisp, pcondisp;
/************/
/************/
/* int obsint = 0; */
/* char obsmes[80]; */
/************/
/* Fill the output array */
for (i = 0; i < rpm -> nur; ++i) {
log -> outarray[PRADI*rpm -> nur+i] = dinterntoparam(par[PRADI*rpm -> nur+i], RADI, hdr, rpm -> ndisks);
for (disk = 0; disk < rpm -> ndisks; ++disk) {
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVROT)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVROT)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VROT, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVRAD)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVRAD)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VRAD, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVVER)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVVER)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VVER, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PDVRO)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PDVRO)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ DVRO, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PDVRA)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PDVRA)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ DVRA, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PDVVE)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PDVVE)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ DVVE, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PZDRO)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZDRO)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ ZDRO, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PZDRA)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZDRA)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ ZDRA, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PZDVE)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZDVE)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ ZDVE, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PZ0 )*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZ0 )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ Z0 , hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSBR )*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSBR )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SBR , hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM1A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM1A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM1P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM1P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM2A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM2A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM2P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM2P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM3A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM3A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM3P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM3P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM4A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM4A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSM4P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM4P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA1A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA1A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA1P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA1P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA1D)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA1D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA1D, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA2A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA2A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA2P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA2P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA2D)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA2D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA2D, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA3A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA3A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA3P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA3P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA3D)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA3D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA3D, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA4A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA4A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA4P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA4P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PGA4D)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA4D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA4D, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PAZ1P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ1P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PAZ1W)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ1W)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ1W, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PAZ2P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ2P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PAZ2W)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ2W)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ2W, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ INCL, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PPA )*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PPA )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ PA , hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PSDIS)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSDIS)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SDIS, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PCLNR)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PCLNR)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ CLNR, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM0A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM0A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM0A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM1A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM1A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM1P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM1P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM2A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM2A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM2P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM2P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM3A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM3A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM3P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM3P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM4A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM4A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVM4P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM4P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA1A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA1A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA1P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA1P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA2A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA2A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA2P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA2P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA3A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA3A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA3P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA3P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA4A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA4A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRA4P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA4P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO1A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO1A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO1P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO1P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO2A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO2A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO2P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO2P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO3A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO3A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO3P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO3P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO4A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO4A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PRO4P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO4P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM0A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM0A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM0A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM1A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM1A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM1P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM1P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM2A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM2A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM2P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM2P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM3A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM3A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM3P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM3P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM4A)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM4A, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PWM4P)*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM4P, hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PLS0 )*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PLS0 )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ LS0 , hdr, rpm -> ndisks);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PLC0 )*rpm -> nur+i] = dinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PLC0 )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ LC0 , hdr, rpm -> ndisks);
/* Now, we have to convert the triplets into internal units */
globin[0] = par[(PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nur+i];
globin[1] = par[(PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nur+i];
globin[2] = par[(PRPARAMS+disk*NDPARAMS+PVSYS)*rpm -> nur+i];
interntoglob(globin, globout, hdr);
log -> outarray[(PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nur+i] = globout[0];
log -> outarray[(PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nur+i] = globout[1];
log -> outarray[(PRPARAMS+disk*NDPARAMS+PVSYS)*rpm -> nur+i] = globout[2];
}
}
pcondisp = (NPARAMS + (rpm -> ndisks - 1)*NDPARAMS);
condisp = pcondisp +1;
log -> outarray[pcondisp*rpm -> nur] = dinterntoparam(par[pcondisp*rpm -> nur], condisp, hdr, rpm -> ndisks);
/* Chisquare */
log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+CHISQ_TABNR] = chisquare;
if (chisquare_red >= 0.0)
log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+RCHISQ_TABNR] = chisquare_red;
else
log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+RCHISQ_TABNR] = chisquare/dof;
/* Acceptance */
log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+ACCEPT_TABNR] = (double) accept;
/* model number */
log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+LOOPNR_TABNR] = (double) modcount;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Writes the information contained in rpm -> par to the output array of rpm */
static void writeoutarrayerr(hdrinf *hdr, ringparms *rpm, double *par, double *errors, char accept, double chisquare, int modcount, double dof)
{
int i;
int disk;
/************/
/************/
/* int obsint = 0; */
/* char obsmes[80]; */
/************/
int condisp, pcondisp;
for (i = 0; i < rpm -> nur; ++i) {
errors[PRADI*rpm -> nur+i] = ddinterntoparam(par[PRADI*rpm -> nur+i], RADI, hdr, rpm -> ndisks);
for (disk = 0; disk < rpm -> ndisks; ++disk) {
errors[(PRPARAMS+disk*NDPARAMS+PVROT)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVROT)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VROT, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVRAD)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVRAD)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VRAD, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVVER)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVVER)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VVER, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PDVRO)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PDVRO)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ DVRO, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PDVRA)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PDVRA)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ DVRA, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PDVVE)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PDVVE)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ DVVE, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PZDRO)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZDRO)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ ZDRO, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PZDRA)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZDRA)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ ZDRA, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PZDVE)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZDVE)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ ZDVE, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PZ0 )*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PZ0 )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ Z0 , hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSBR )*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSBR )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SBR , hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM1A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM1A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM1P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM1P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM2A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM2A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM2P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM2P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM3A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM3A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM3P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM3P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM4A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM4A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PSM4P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PSM4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ SM4P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA1A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA1A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA1P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA1P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA1D)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA1D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA1D, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA2A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA2A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA2P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA2P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA2D)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA2D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA2D, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA3A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA3A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA3P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA3P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA3D)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA3D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA3D, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA4A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA4A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA4P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA4P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PGA4D)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PGA4D)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ GA4D, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PAZ1P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ1P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PAZ1W)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ1W)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ1W, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PAZ2P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ2P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PAZ2W)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PAZ2W)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ AZ2W, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ INCL, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PPA )*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PPA )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ PA , hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ XPOS, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ YPOS, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVSYS)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVSYS)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VSYS, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM0A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM0A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM0A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM1A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM1A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM1P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM1P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM2A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM2A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM2P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM2P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM3A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM3A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM3P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM3P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM4A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM4A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PVM4P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PVM4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ VM4P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA1A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA1A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA1P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA1P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA2A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA2A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA2P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA2P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA3A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA3A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA3P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA3P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA4A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA4A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRA4P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRA4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RA4P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO1A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO1A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO1P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO1P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO2A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO2A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO2P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO2P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO3A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO3A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO3P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO3P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO4A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO4A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PRO4P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PRO4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ RO4P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM0A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM0A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM0A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM1A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM1A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM1A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM1P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM1P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM1P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM2A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM2A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM2A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM2P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM2P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM2P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM3A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM3A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM3A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM3P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM3P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM3P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM4A)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM4A)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM4A, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PWM4P)*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PWM4P)*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ WM4P, hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PLS0 )*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PLS0 )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ LS0 , hdr, rpm -> ndisks);
errors[(PRPARAMS+disk*NDPARAMS+PLC0 )*rpm -> nur+i] = ddinterntoparam(par[(PRPARAMS+disk*NDPARAMS+PLC0 )*rpm -> nur+i], PRPARAMS+disk*NDPARAMS+ LC0 , hdr, rpm -> ndisks);
}
}
pcondisp = (NPARAMS + (rpm -> ndisks - 1)*NDPARAMS);
condisp = pcondisp +1;
errors[(pcondisp)*rpm -> nur] = ddinterntoparam(par[(pcondisp)*rpm -> nur], condisp, hdr, rpm -> ndisks);
/* Chisquare */
errors[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+CHISQ_TABNR] = chisquare;
errors[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+RCHISQ_TABNR] = chisquare/dof;
/* Acceptance */
errors[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+ACCEPT_TABNR] = (double) accept;
/* model number */
errors[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+LOOPNR_TABNR] = (double) modcount;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Delivers a random variable according to a profile identifyer */
static float zprof(int option, maths_rstrf *permrandstr, float *y2)
{
/* Note: y1 is basically uninitialised for case 1 UNLESS it is initialised by calling zprof(6,randstr) before. This is (hopefully done throughout the program) */
float x1, x2, w;
static float y1 = 0.0;
/* static float y2; */
switch (option) {
case 1:
if (*y2 < -1000.0) {
/* According to http://www.taygeta.com/random/gaussian.html a gaussian distribution with sigma = 1 and mean 0, unfortunately two independent numbers are generated */
do {
x1 = 2.0*maths_rndmf(permrandstr)-1.0;
x2 = 2.0*maths_rndmf(permrandstr)-1.0;
w = x1*x1+x2*x2;
} while (w >= 1.0);
w = sqrtf((-2.0*logf(w))/w);
y1 = x1*w;
*y2 = x2*w;
}
else {
y1 = *y2;
*y2 = -1024.0;
}
break;
/* Sech2 */
case 2:
/* sech2: 0.5*sech^2(x) or 1/(2*Z0)*sech^2(z/Z0) (normalised to 1) */
while (!((x1 = 2.0*maths_rndmf(permrandstr)-1.0)-1.0))
;
/* Note that this is the same as 0.5 log(p/(1-p)) if p varies from 0 to 1, so this is correct */
y1 = atanhf(x1);
break;
/* exponential exp(-|x|)/2 or with Z0 exp(-|x/Z0|)/(2*Z0) (normalised to 1) */
case 3:
while (!((x1 = 2.0*maths_rndmf(permrandstr)-1.0)))
;
if (x1 > 0.0)
y1 = -logf(x1);
else if (x1 < 0.0)
y1 = logf(-x1);
break;
case 4:
/* Lorentzian layer: (1/pi)/(x^2+1) or with Z0: Z0/(pi*(x^2+Z0^2)) (normalised to 1) */
while (!((x1 = 2.0*maths_rndmf(permrandstr)-1.0)-1.0))
;
/* this is correct */
y1 = tanf(PIHALF*x1);
break;
case 6:
*y2 = -1024.0;
y1 = 0.0;
break;
default:
/* Uniform layer 1/2 for -1<x<1 0 otherwise or with Z0: 1/(2*Z0) for -Z0<z<Z0 0 otherwise */
y1 = 2.0*maths_rndmf(permrandstr)-1.0;
break;
}
return y1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Initializes the standard header context table */
static int hdl_init(int ndisks)
{
int disk;
char placer[9];
if (ftstab_hdladditem("RADI", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VROT", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VRAD", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VVER", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("DVRO", "VELO/ANGLE", "km/s/arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("DVRA", "VELO/ANGLE", "km/s/arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("DVVE", "VELO/ANGLE", "km/s/arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ZDRO", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ZDRA", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ZDVE", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("Z0" , "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SBR" , "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1000.0) < 0) { return 0;}
if (ftstab_hdladditem("SM1A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SM1P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SM2A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SM2P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SM3A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SM3P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SM4A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SM4P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA1A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA1P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA1D", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA2A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA2P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA2D", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA3A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA3P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA3D", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA4A", "FLUX" , "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA4P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("GA4D", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("AZ1P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("AZ1W", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("AZ2P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("AZ2W", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("INCL", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PA" , "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("XPOS", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("YPOS", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VSYS", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SDIS", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("CLNR", "NATURAL" , " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM0A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM1A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM1P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM2A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM2P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM3A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM3P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM4A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("VM4P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM0A", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM1A", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM1P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM2A", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM2P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM3A", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM3P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM4A", "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WM4P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("LS0" , "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("LC0" , "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO1A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO1P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO2A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO2P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO3A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO3P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO4A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RO4P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA1A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA1P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA2A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA2P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA3A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA3P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA4A", "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RA4P", "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
for (disk = 1; disk < ndisks; ++disk) {
sprintf(placer, "VROT_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VRAD_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VVER_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "DVRO_%i", disk+1); if (ftstab_hdladditem(placer, "VELO/ANGLE", "km/s/arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "DVRA_%i", disk+1); if (ftstab_hdladditem(placer, "VELO/ANGLE", "km/s/arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "DVVE_%i", disk+1); if (ftstab_hdladditem(placer, "VELO/ANGLE", "km/s/arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "ZDRO_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "ZDRA_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "ZDVE_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "Z0_%i" , disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SBR_%i" , disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1000.0) < 0) { return 0;}
sprintf(placer, "SM1A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SM1P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SM2A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SM2P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SM3A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SM3P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SM4A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SM4P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA1A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA1P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA1D_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA2A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA2P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA2D_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA3A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA3P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA3D_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA4A_%i", disk+1); if (ftstab_hdladditem(placer, "FLUX", "Jy*m/(s*arcsec**2)", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA4P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "GA4D_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "AZ1P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "AZ1W_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "AZ2P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "AZ2W_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "INCL_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "PA_%i" , disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "XPOS_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "YPOS_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VSYS_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "SDIS_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "CLNR_%i", disk+1); if (ftstab_hdladditem(placer, "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM0A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM1A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM1P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM2A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM2P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM3A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM3P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM4A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "VM4P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM0A_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM1A_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM1P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM2A_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM2P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM3A_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM3P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM4A_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "WM4P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "LS0_%i" , disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "LC0_%i" , disk+1); if (ftstab_hdladditem(placer, "ANGLE", "arcsec", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO1A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO1P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO2A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO2P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO3A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO3P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO4A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RO4P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA1A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA1P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA2A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA2P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA3A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA3P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA4A_%i", disk+1); if (ftstab_hdladditem(placer, "VELO", "km/s", 0.0, 1.0) < 0) { return 0;}
sprintf(placer, "RA4P_%i", disk+1); if (ftstab_hdladditem(placer, "ANGLE", "deg", 0.0, 1.0) < 0) { return 0;}
}
if (ftstab_hdladditem("CONDISP" , "VELO" , "km/s" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("BMAJ" , "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("BMIN" , "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("BPA" , "ANGLE" , "deg" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RMS" , "FLUX" , "Jy*km/s*beam", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("NUR" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RADSEP" , "ANGLE" , "arcsec" , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("WEIGHT" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("MODE" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ISEED" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("LOOPS" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("NCORES" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ISEED_2" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ANSTART" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ANEND" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ANSTEPS" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("INIMODE" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("FITMODE" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("OUTCUBUP", "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("DISTANCE", "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PENALTY" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RFREQ" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ITOU" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("MAXITER" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("CALLITE" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SIZE" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSSE" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSNP" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSCO" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSSO" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSMV" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSNF" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSII" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSFI" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSID" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PSDD" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("NUR" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("INTY" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("INDINTY" , "NATURAL", " " , 0.0, 1.0) < 0) { return 0;}
for (disk = 1; disk < ndisks; ++disk) {
/* NOTE: this used to be sprintf(placer, "LTYPE_%i" , disk+1); */
sprintf(placer, "LTYPE_%i" , disk+1);
if (ftstab_hdladditem(placer, "NATURAL", " ", 0.0, 1.0) < 0)
{ return 0;}
}
if (ftstab_hdladditem("CFLUX", "FLUX", "Jy*km/s", 0.0, 1.0) < 0) { return 0;}
for (disk = 1; disk < ndisks; ++disk) {
/* NOTE: this used to be sprintf(placer, "CFLUX_%i" , disk+1); */
sprintf(placer, "CFLUX_%i" , disk+1);
if (ftstab_hdladditem(placer, "FLUX", "Jy*km/s", 0.0, 1.0) < 0)
{ return 0;}
}
/* Second hdu */
if (ftstab_hdladditem("PARMAX" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("PARMIN" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("MODERATE", "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("DELSTART", "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("DELEND" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ITESTART", "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ITEEND" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("SATDELT" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("MINDELTA", "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ELEMENTS", "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
/* Third hdu */
if (ftstab_hdladditem("CHISQ" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("RCHISQ" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("LOOPNR" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
if (ftstab_hdladditem("ACCEPT" , "NATURAL", " ", 0.0, 1.0) < 0) { return 0;}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Opens if necessary creat the third hdu */
static int open_hdu_3(loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
if (fit -> fitmode == GOLDEN_SECTION) {
/* Now we get the number of loops */
fit -> loopnr = 0;
}
else if (fit -> fitmode > GOLDEN_SECTION) {
fit -> recnr = 0;
fit -> loopnr = 1;
}
else
goto error;
return 0;
error:
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Calculates and puts the results of the fitting procedure */
static int putgenresults(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
double *errors = NULL, *array = NULL;
int i;
size_t size_tv, length;
double doublev, chimult = 1.0;
char solpres = 1;
int disk;
char mes[200];
int dev = 1;
double solchisq;
/* Get the best-fit chisquare and check if we had a solution*/
if (gft_mst_get(fit -> gft_mstv, &solchisq, GFT_OUTPUT_SOLCHSQ)) {
if (!gft_mst_get(fit -> gft_mstv, &fit -> mon_bestchisq, GFT_OUTPUT_BESTCHISQ))
solpres = 2;
else
solpres = 0;
}
gft_mst_get(fit -> gft_mstv, &fit -> mon_size, GFT_OUTPUT_SIZE);
/* Allocate the error array */
if (!(errors = (double *) malloc(((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR)*sizeof(double))))
goto error;
/* Get the number of elements in varlist */
if (solpres) {
gft_mst_get(fit -> gft_mstv, &size_tv, GFT_OUTPUT_NPAR);
/* Allocate a double array of this length */
if ((size_tv)) {
if (!(array = (double *) malloc (size_tv*sizeof(double))))
goto error;
}
if ((solpres == 1)) {
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR; ++i)
errors[i] = 0.0;
/* Get the best-fit parameters therein */
if (gft_mst_get(fit -> gft_mstv, array, GFT_OUTPUT_SOLPAR)) {
free(array);
free(errors);
return 1;
}
}
else if (solpres == 2) {
if (gft_mst_get(fit -> gft_mstv, array, GFT_OUTPUT_BESTPAR)) {
free(array);
free(errors);
return 1;
}
}
}
/* Now calculate the parameters from that and copy to oldpar */
if (solpres){
chimult = pow(OUTRANGEFAC,chprm_gen(array, fit -> varylist, rpm -> par));
/* if (chprm_gen(array, fit -> varylist, rpm -> par)) */
/* If they get out of range, we multiply the chisquare by OUTRANGEFAC */
/* chimult = OUTRANGEFAC; */
/* else */
/* chimult = 1.0; */
}
/* Now ensure that the indexed parameters are aligned */
for (i = rpm -> nur*NSSDPARAMS; i < rpm -> nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i) {
rpm -> chapar[i] = chkchangep(fit -> varylist, fit -> fitmode, i, rpm -> nur);
}
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
/* When ending make one run of interpover */
interpover(rpm, rpm -> radsep, 1, NULL, fit -> index);
/* Do make the model */
galmod(hdr, rpm, GENFIT, fit -> varylist, fit -> index, fit -> fluxpoints, fit -> npoints);
/* Get the chisquare */
/* use here the usual replacement of PCONDISP */
doublev = chimult*(reg_do(fit -> reg_contv, (fit -> mon_alloops == fit -> loops)?fit -> loops - 1:fit -> mon_alloops, getchisquare_c(rpm -> par[((NPARAMS + (rpm -> ndisks - 1)*NDPARAMS))*rpm -> nur]))+((double) rpm -> outpoints)*rpm -> penalty);
/* report */
sprintf(mes,
"Finished " /* Fitting */
"N:%d", /* Number of pointsources */
fit -> npoints[0]);
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%d", /* Number of pointsources */
fit -> npoints[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" F:%.2E", /* Total flux */
fit -> fluxpoints[0]*rpm -> cflux[0]*hdr -> deltgridtouser[2]);
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%.2E",
fit -> fluxpoints[disk]*rpm -> cflux[disk]*hdr -> deltgridtouser[2]);
}
length = strlen(mes);
sprintf(mes+length,
" C:%E " /* current chisquare */
" S:%E ", /* size */
doublev, /* current minimum chisquare */
fit -> mon_size /* size */
);
anyout_tir(&dev, mes);
/* New Kamphuis */
if (startinfv -> restartid) {
length = strlen(mes);
sprintf(mes+length,
" R:%i ", /* current restart-id */
startinfv -> restartid /* size */
);
}
progressout(startinfv, mes);
/* error source ? */
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS; ++i) {
rpm -> oldpar[i] = rpm -> par[i];
}
/* This does not work for some reason, has to be addressed in gft. Nasty hack? */
/*
if (gft_mst_get(fit -> gft_mstv, &doublev2, GFT_OUTPUT_SOLCHSQRED)) {
gft_mst_get(fit -> gft_mstv, &doublev2, GFT_OUTPUT_ACTCHISQRED);
gft_mst_get(fit -> gft_mstv, &doublev, GFT_OUTPUT_ACTCHISQ);
}
*/
/* instead we use what we get from the last model */
/* make the output array */
writeoutarray(log, hdr, rpm, rpm -> par, 1, doublev, fit -> recnr, fit -> dof, -1.0);
/* Errors are 0 if there are none, we use the par array to indicate that */
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur + NSPARAMS; ++i)
rpm -> par[i] = 0.0;
/* get the errors */
if (!gft_mst_get(fit -> gft_mstv, array, GFT_OUTPUT_SOLERR))
chprm_gen(array, fit -> varylist, rpm -> par);
/* Go through the parameters */
writeoutarrayerr(hdr, rpm, rpm -> par, errors, 1, 0.0, 0, fit -> dof);
/* Put it to the grid */
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR; ++i) {
/* ftstab_fillhd(i, ftstab_get_coltit(i+1), ftstab_get_coltyp(i+1), errors[i], log -> outarray[i]); */
tir_fillhd(log, i, errors[i], log -> outarray[i]);
}
/* Apply the changes */
/* if (!ftstab_clearhd(0)) */
/* goto error; */
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS; ++i) {
rpm -> par[i] = rpm -> oldpar[i];
}
if ((errors))
free(errors);
if ((array))
free(array);
return 1;
error:
if ((errors))
free(errors);
if ((array))
free(array);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* A golden section iteration */
static int golden_section(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
int i,j;
int accept = 1;
long bigloops;
varlel *varele;
varlel *varele2;
double delta;
double delta_start;
int maxiter;
int curiter;
int satisfied;
int globiter = 0;
int globiter_old;
int def = 1;
char mes[300];
char key[20];
double *prevresult;
int nmax = 0;
double chimult;
/* double mdelt; */
int disk;
size_t length;
for (i=0; i<100000000; ++i)
;
/* Get the number of elements in the varlist */
varele = fit -> varylist;
i = 0;
while (varele) {
++i;
nmax = (nmax > varele -> nelem) ? nmax: varele -> nelem;
varele = varele -> next;
}
/* The degrees of freedom are determined by the amount of variable
parameters, we do it VERY roughly. If there is a parameter varied
twice, this is not true anymore */
/* dof = (hdr -> bsize1-1)*hdr -> bsize2* hdr -> nsubs-i; */
/* We allocate the prevresult array */
if (!(prevresult = (double *) malloc(nmax*sizeof(double))))
return 0;
/* Now get the number of big loops */
/* if (ftstab_get_rownr_()) */
/* bigloops = (fit -> loopnr)/i+1+!((fit -> loopnr)%i); */
/* else { */
bigloops = 0;
/* } */
bigloops = (fit -> loopnr != 0)?(fit -> loopnr-1)/i+1:0;
/* Now put the pointer to the next element in the varlel */
if ((fit -> loopnr))
i = (fit -> loopnr-1)%i;
else
i = 0;
varele = fit -> varylist;
for (j = 0; j < i; ++j)
varele = varele -> next;
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
/* The new parameter list will be created */
if (!(fit -> loopnr)) {
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i)
rpm -> oldpar[i] = rpm -> par[i];
}
else {
if (changedependent(rpm, rpm -> oldpar, fit -> index, rpm -> chapar) < 0)
goto error;
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i)
rpm -> par[i] = rpm -> oldpar[i];
}
/* When starting make one run of interpover */
interpover(rpm, rpm -> radsep, 1, NULL, fit -> index);
/* Get the old chisqare or initialise */
if ((fit -> loopnr)) {
hdr -> oldchi2 = log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+CHISQ_TABNR-1];
satisfied = log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+ACCEPT_TABNR-1];
}
else {
/* addendum: change penalising strategy also for this task */
varele2 = fit -> varylist;
chimult = 1.0;
while(varele2) {
for (i = 0; i < varele2 -> nelem; ++i) {
if (maths_checkinbetw(varele2 -> parmax, varele2 -> parmin, rpm -> par[varele2 -> elements[i]])) {
/* If they get out of range, we multiply the chisquare by OUTRANGEFAC */
chimult = chimult*OUTRANGEFAC;
break;
}
}
varele2 = varele2 -> next;
}
/* Do it */
galmod(hdr, rpm, 1, varele, fit -> index, rpm -> fluxpoints, fit -> npoints);
/* Get the chisquare */
hdr -> chi2 = getchisquare_c(rpm -> par[((NPARAMS + (rpm -> ndisks - 1)*NDPARAMS))*rpm -> nur]);
/* Regularise */
hdr -> chi2 = reg_do(fit -> reg_contv, fit -> loopnr, hdr -> chi2);
/* For bookkeeping */
fit -> mon_alloops = fit -> loopnr;
/* Correct the chisquare taking into account the outliers, don't know if that is necessary here... */
hdr -> chi2 = chimult*(hdr -> chi2+((double) rpm -> outpoints)*rpm -> penalty);
/* Copy it */
hdr -> oldchi2 = hdr -> chi2;
/* Write the output */
satisfied = 1;
/* Starting */
sprintf(mes, "START");
anyout_tir(&def, mes);
writeoutput(log, hdr, rpm, fit, satisfied, fit -> dof, bigloops, globiter);
++fit -> loopnr;
++bigloops;
}
/* This will run until the bigloops is reached */
while (bigloops <= fit -> loops) {
/* We go through the varylist */
while(varele) {
/* Record where we started */
for (i = 0; i < varele -> nelem; ++i)
prevresult[i] = rpm -> oldpar[varele -> elements[i]];
/* Reset the old chisquare */
/* chi2_old = hdr -> oldchi2 ; */
globiter_old = globiter;
/* Calculate the delta */
if (bigloops - varele -> moderate <= 0)
delta = (bigloops-1)*(varele -> delend-varele -> delstart)/varele -> moderate+varele -> delstart;
else
delta = varele -> delend;
delta_start = delta;
/* Calculate the number of steps */
if (bigloops - varele -> moderate <= 0)
maxiter = ((bigloops-1)*(varele -> iteend-varele -> itestart))/varele -> moderate+varele -> itestart;
else
maxiter = varele -> iteend;
/* The first iteration */
curiter = 0;
accept = 1;
/* We go on searching until we find a lower chisquare and then a higher chisquare */
while (1) {
/* If the maximum number of iterations is reached break out, deeply disappointed */
if (curiter == maxiter) {
accept = 0;
satisfied = 0;
break;
}
/* Change the params */
for (i = 0; i < varele -> nelem; ++i)
rpm -> par[varele -> elements[i]] = rpm -> oldpar[varele -> elements[i]] + delta;
/* addendum: change penalising strategy also for this task */
/* addendum: change penalising strategy also for this task */
varele2 = fit -> varylist;
chimult = 1.0;
while(varele2) {
for (i = 0; i < varele2 -> nelem; ++i) {
if (maths_checkinbetw(varele2 -> parmax, varele2 -> parmin, rpm -> par[varele2 -> elements[i]])) {
/* If they get out of range, we multiply the chisquare by OUTRANGEFAC */
chimult = chimult*OUTRANGEFAC;
break;
}
}
varele2 = varele2 -> next;
}
/* Reset the touched array */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = chkchangep(varele, fit -> fitmode, i, rpm -> nur);
/* check and change the index */
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
/* Do it */
for (i = 0; i < rpm -> ndisks; ++i)
rpm -> fluxpoints[i] = 0;
galmod(hdr, rpm, 1, varele, fit -> index, rpm -> fluxpoints, fit -> npoints);
++globiter;
/* Get the chisquare */
hdr -> chi2 = getchisquare_c(rpm -> par[((NPARAMS + (rpm -> ndisks - 1)*NDPARAMS))*rpm -> nur]);
/* Regularise */
hdr -> chi2 = reg_do(fit -> reg_contv, bigloops-1, hdr -> chi2);
fit -> mon_alloops = bigloops-1;
/* Correct the chisquare taking into account the outliers, don't know if that is necessary here... */
hdr -> chi2 = chimult*(hdr -> chi2+((double) rpm -> outpoints)*rpm -> penalty);
/* ftstab_putcoltitl(key, ftstab_get_coltit(*varele -> elements+1)); */
ftstab_putcoltitl(key, (*varele -> elements)/rpm -> nur+1);
/* Report Search minimum, big loops, keyword loops, total models, keyword, first ringnumber, keyword models/maxmodels, number of pointsources, total flux, current minimum chisquare, trial chisquare, difference, current stepwidth, start stepwidth. In principle, this should be a status report, but gipsy... crashes when you interrupt the task if you change the length MSGLEN of the status line in taskcom.h */
sprintf(mes,
"SM " /* Searching minimum */
"BL:%li " /* Big loops */
"KL:%li " /* Keyword loops */
"TM:%i " /* Total models */
"KW:%s " /* Keyword */
"FR:%i " /* First ringnumber */
"KM:%i" /* Keyword models */
"/%i " /* Keyword maxmodels */
"NP:%d", /* Number of pointsources */
bigloops, /* Big loops */
fit -> loopnr, /* Keyword loops */
globiter, /* Total models */
key, /* Keyword */
(*varele -> elements/rpm -> nur < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS))?*varele -> elements%rpm -> nur+1:1, /* First ringnumber */
globiter-globiter_old, /* Keyword models */
maxiter, /* Keyword maxmodels */
fit -> npoints[0]); /* Number of pointsources */
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%d", /* Number of pointsources */
fit -> npoints[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" TF:%.2E", /* Total flux */
rpm -> fluxpoints[0]*rpm -> cflux[0]);
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%.2E",
rpm -> fluxpoints[disk]*rpm -> cflux[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" CC:%E " /* current minimum chisquare */
"DC:%+.1E " /* Difference */
"SW:%+.2E" /* Current stepwidth */
"/%.2E " /* Start stepwidth */
"AC:%i", /* Acceptance flag */
hdr -> oldchi2, /* current minimum chisquare */
hdr -> oldchi2-hdr -> chi2, /* Difference */
ddinterntoparam(delta, (*varele -> elements)/rpm -> nur +1, hdr, rpm -> ndisks), /* Current stepwidth */
ddinterntoparam(delta_start, (*varele -> elements)/rpm -> nur +1, hdr, rpm -> ndisks), /* Start stepwidth */
satisfied /* Acceptance flag */
);
anyout_tir(&def, mes);
/* Now compare */
if (hdr -> chi2 >= hdr -> oldchi2) {
/* If the number of iterations is larger than 1, we stop it here */
if (curiter > 0) {
delta = BFAC*delta;
++curiter;
break;
}
/* If not we search in the other direction */
else {
delta = -delta;
}
}
else {
/* Now overwrite the oldparams */
for (i = 0; i < varele -> nelem; ++i)
rpm -> oldpar[varele -> elements[i]] = rpm -> oldpar[varele -> elements[i]] + delta;
/* check and change the index */
if (changedependent(rpm, rpm -> oldpar, fit -> index, rpm -> chapar) < 0)
goto error;
/* Now enlarge the delta and accept the chisquare */
hdr -> oldchi2 = hdr -> chi2;
if (curiter < MAGNIFICNR)
delta = AFAC*delta;
}
++curiter;
}
/* search = 1; */
if ((accept)) {
/* We go on searching to find the minimum in the knowledge that we are nearly there */
while (1) {
/* If the maximum number of iterations is reached break out, deeply disappointed */
if (curiter == maxiter) {
satisfied = 0;
break;
}
/* Change the delta */
delta = BFAC * delta;
/* Check if we break out because of too small deltas*/
if (fabs(delta) < varele -> mindelta)
break;
for (i = 0; i < varele -> nelem; ++i)
rpm -> par[varele -> elements[i]] = rpm -> oldpar[varele -> elements[i]] + delta;
/* addendum: change penalising strategy also for this task */
varele2 = fit -> varylist;
chimult = 1.0;
while(varele2) {
for (i = 0; i < varele2 -> nelem; ++i) {
if (maths_checkinbetw(varele2 -> parmax, varele2 -> parmin, rpm -> par[varele2 -> elements[i]])) {
/* If they get out of range, we multiply the chisquare by OUTRANGEFAC */
chimult = chimult*OUTRANGEFAC;
break;
}
}
varele2 = varele2 -> next;
}
/* check out the indexed parameters */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = chkchangep(varele, fit -> fitmode, i, rpm -> nur);
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
/* We don't have to check whether we broke out of range */
/* Do it */
galmod(hdr, rpm, 1, varele, fit -> index, rpm -> fluxpoints, fit -> npoints);
++globiter;
/* Get the chisquare */
hdr -> chi2 = getchisquare_c(rpm -> par[((NPARAMS + (rpm -> ndisks - 1)*NDPARAMS))*rpm -> nur]);
/* Regularise */
hdr -> chi2 = reg_do(fit -> reg_contv, bigloops-1, hdr -> chi2);
fit -> mon_alloops = bigloops-1;
/* Correct the chisquare taking into account the outliers, don't know if that is necessary here... */
hdr -> chi2 = chimult*(hdr -> chi2+((double) rpm -> outpoints)*rpm -> penalty);
/* Report Found minimum, big loops, total models, keyword loops, keyword, first ringnumber, keyword models/maxmodels, number of pointsources, total flux, current minimum chisquare, trial chisquare, difference, current stepwidth, start stepwidth */
/* Report Search minimum, big loops, keyword loops, total models, keyword, first ringnumber, keyword models/maxmodels, number of pointsources, total flux, current minimum chisquare, trial chisquare, difference, current stepwidth, start stepwidth */
sprintf(mes,
"FM " /* Searching minimum */
"BL:%li " /* Big loops */
"KL:%li " /* Keyword loops */
"TM:%i " /* Total models */
"KW:%s " /* Keyword */
"FR:%i " /* First ringnumber */
"KM:%i" /* Keyword models */
"/%i " /* Keyword maxmodels */
"NP:%d", /* Number of pointsources */
bigloops, /* Big loops */
fit -> loopnr, /* Keyword loops */
globiter, /* Total models */
key, /* Keyword */
(*varele -> elements/rpm -> nur < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS))?*varele -> elements%rpm -> nur+1:1, /* First ringnumber */
globiter-globiter_old, /* Keyword models */
maxiter, /* Keyword maxmodels */
fit -> npoints[0]); /* Number of pointsources */
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%d", /* Number of pointsources */
fit -> npoints[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" TF:%.2E", /* Total flux */
rpm -> fluxpoints[0]*rpm -> cflux[0]);
for (disk = 1; disk < rpm -> ndisks; ++disk) {
length = strlen(mes);
sprintf(mes+length,
"/%.2E",
rpm -> fluxpoints[disk]*rpm -> cflux[disk]);
}
length = strlen(mes);
sprintf(mes+length,
" CC:%E " /* current minimum chisquare */
"DC:%+.1E " /* Difference */
"SW:%+.2E" /* Current stepwidth */
"/%.2E " /* Start stepwidth */
"AC:%i", /* Acceptance flag */
hdr -> oldchi2, /* current minimum chisquare */
hdr -> oldchi2-hdr -> chi2, /* Difference */
ddinterntoparam(delta, (*varele -> elements)/rpm -> nur+1, hdr, rpm -> ndisks), /* Current stepwidth */
ddinterntoparam(delta_start, (*varele -> elements)/rpm -> nur+1, hdr, rpm -> ndisks), /* Start stepwidth */
satisfied /* Acceptance flag */
);
anyout_tir(&def, mes);
/* Now compare */
if (hdr -> chi2 >= hdr -> oldchi2) {
delta = -delta;
}
else {
/* Now overwrite the oldparams */
for (i = 0; i < varele -> nelem; ++i)
rpm -> oldpar[varele -> elements[i]] = rpm -> oldpar[varele -> elements[i]] + delta;
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = chkchangep(varele, fit -> fitmode, i, rpm -> nur);
/* check out the indexed parameters */
if (changedependent(rpm, rpm -> oldpar, fit -> index, rpm -> chapar) < 0)
goto error;
hdr -> oldchi2 = hdr -> chi2;
}
++curiter;
}
}
/*Output of a progress file Kamphuis addition */
progressout(startinfv, mes);
/* We have to check whether we have changed too much to be satisfied */
if ((satisfied)) {
/* We only have to check one variable */
if (fabs(rpm -> oldpar[varele -> elements[0]]-prevresult[0]) > varele -> satdelt) {
satisfied = 0;
}
}
/* Check the range of the params, this is old */
/* Deleted everything START */
/* for (i = 0; i < varele -> nelem; ++i) { */
/* if (maths_checkinbetw(varele -> parmax, varele -> parmin, rpm -> oldpar[varele -> elements[i]])) { */
/* Comment on that */
/* sprintf(mes, "Parameter out of range, interpolating"); */
/* anyout_tir(&def, mes); */
/***************/
/* This is new */
/***************/
/* Find out what has happened */
/* mdelt = 0 */
/* mdelt = fabs(prevresult[i] - rpm -> oldpar[varele -> elements[i]])/2.0; */
/* if (varele -> parmax > varele -> parmin) { */
/* if (rpm -> oldpar[varele -> elements[i]] < varele -> parmin) { */
/* while (i < varele -> nelem) { */
/* mdelt = (((prevresult[i]-varele -> parmin)/2.0) < mdelt)?((prevresult[i]-varele -> parmin)/2.0):mdelt; */
/* mdelt = (fabs(prevresult[i]-varele -> parmin) < mdelt)?(fabs(prevresult[i]-varele -> parmin)/2.0):mdelt; */
/* ++i; */
/* } */
/* mdelt = -mdelt; */
/* } */
/* else { */
/* while (i < varele -> nelem) { */
/* mdelt = (((varele -> parmax-prevresult[i])/2.0) < mdelt)?(((varele -> parmax-prevresult[i])/2.0)/2.0):mdelt; */
/* mdelt = (fabs(prevresult[i]-varele -> parmax) < mdelt)?(fabs(prevresult[i]-varele -> parmax)/2.0):mdelt; */
/* ++i; */
/* } */
/* } */
/* } */
/* else { */
/* if (rpm -> oldpar[varele -> elements[i]] < varele -> parmax) { */
/* while (i < varele -> nelem) { */
/* mdelt = (((prevresult[i]-varele -> parmax)/2.0) < mdelt)?((prevresult[i]-varele -> parmax)/2.0):mdelt; */
/* mdelt = (fabs(prevresult[i]-varele -> parmax) < mdelt)?(fabs(prevresult[i]-varele -> parmax)/2.0):mdelt; */
/* ++i; */
/* } */
/* mdelt = -mdelt; */
/* } */
/* else { */
/* while (i < varele -> nelem) { */
/* mdelt = (((varele -> parmin-prevresult[i])/2.0) < mdelt)?(((varele -> parmin-prevresult[i])/2.0)/2.0):mdelt; */
/* mdelt = (fabs(prevresult[i]-varele -> parmin) < mdelt)?(fabs(prevresult[i]-varele -> parmin)/2.0):mdelt; */
/* ++i; */
/* } */
/* } */
/* } */
/* change all the values: new */
/* for (i = 0; i < varele -> nelem; ++i) */
/* rpm -> par[varele -> elements[i]] = rpm -> oldpar[varele -> elements[i]] = prevresult[i]+mdelt; */
/* check out the indexed parameters */
/* changedependent(rpm, rpm -> par, fit -> index); */
/* changedependent(rpm, rpm -> oldpar, fit -> index); */
/* write back all the values: old */
/* for (i = 0; i < varele -> nelem; ++i) */
/* rpm -> par[varele -> elements[i]] = rpm -> oldpar[varele -> elements[i]] = prevresult[i]; */
/* This is crucial at that point */
/* interpover(rpm, rpm -> radsep, 1, varele, fit -> index); */
/* Do it */
/* galmod(hdr, rpm, 1, varele, fit -> index, fluxpoints, fit -> npoints); */
/* Get the chisquare */
/* hdr -> chi2 = getchisquare_c(rpm -> par[(PCONDISP)*rpm -> nur]); */
/* Regularise */
/* hdr -> chi2 = reg_do(fit -> reg_contv, bigloops-1, hdr -> chi2); */
/* fit -> mon_alloops = bigloops-1; */
/* Correct the chisquare taking into account the outliers, don't know if that is necessary here... */
/* hdr -> chi2 = hdr -> chi2+((double) rpm -> outpoints)*rpm -> penalty; */
/* hdr -> oldchi2 = hdr -> chi2; */
/* satisfied = 0; */
/* break; */
/* } */
/* } */
/* BUGFIXED? The following lines were not present in the previous version */
/* Write oldpar into par */
for (i = 0; i < varele -> nelem; ++i)
rpm -> par[varele -> elements[i]] = rpm -> oldpar[varele -> elements[i]];
/* check out the indexed parameters */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
/* BUGFIX: This seems to be very important in order not to loose pointsources; if not done, a pointsource list might be terminated the wrong way */
interpover(rpm, rpm -> radsep, 1, varele, fit -> index);
writeoutput(log, hdr, rpm, fit, satisfied, fit -> dof, fit -> loopnr, globiter);
varele = varele -> next;
/* Now we document on the results */
++fit -> loopnr;
if ((*hdr -> outset != '\0')) {
if (!(fit -> loopnr%hdr -> outcubup)) {
writemodel(hdr, rpm, fit, rpm -> oldpar, fit -> index);
}
}
}
/* If we are still satisfied, we break, because we have results, which is documented also in outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS-1+ACCEPT_TABNR] */
if ((satisfied)) {
break;
}
/* We start at the start of the varylist again */
varele = fit -> varylist;
++bigloops;
satisfied = 1;
}
free(prevresult);
return 1;
error:
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Calculates and puts the results of the fitting procedure */
static int putgoldresults(loginf *log, ringparms *rpm, fitparms *fit)
{
int i;
/* The best value is at the end */
/* ftstab_get_row(fit -> loopnr, log -> outarray); */
/* This is probably stupid, but, well... */
tir_get_register(log, rpm, log -> outarray);
/* Put it to the grid */
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+OUTTABNR; ++i)
/* ftstab_fillhd(i, ftstab_get_coltit(i+1), ftstab_get_coltyp(i+1), COLRADI_DEFAULT, log -> outarray[i]); */
tir_fillhd(log, i, COLRADI_DEFAULT, log -> outarray[i]);
/* Apply the changes */
/* if (!ftstab_clearhd(0)) */
/* goto error; */
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Writes an ascii table with the results */
static int writeasctable(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
int def = 2;
int nel = 1;
int rring;
int err = 1;
char mes[81];
FILE *stream;
int i, j;
char key[21];
char key2[26];
double value;
double delta;
double vsys;
double nu;
double nv[3];
double nvtot[3];
double nrefr[3];
double cosp;
double sinp;
double sini;
double cosi;
double pp[3];
double posin[3];
double posout[3];
/**********/
/**********/
/* int obsint; */
/* char obsmes[81]; */
/*********/
/* First check if there was an input */
if (*log -> table == '\0')
return 1;
/* Also check if there was a logfile and stop if there wasn't */
/* if (*log -> logname == '\0') */
/* return 0; */
rring = rpm -> nur >= 5?5:rpm -> nur;
/* Get the reference ring */
sprintf(mes, "Give reference ring for warp angle calculation");
while ((err)) {
userint_tir(startinfv -> arel, &rring, &nel, &def, "REFRING=", mes);
if (rring <= 0 || rring > rpm -> nur) {
sprintf(mes, "REFRING: impossible number");
cancel_tir(startinfv -> arel, "REFRING=", 2);
def = 4;
}
else
err = 0;
}
/* Try to open the output file */
if (!(stream = fopen(log -> table, "r"))) {
/* If the file doesn't exist we compose a header */
if (!(stream = fopen(log -> table, "w"))) {
return 0;
}
}
else {
if (!(stream = fopen(log -> table, "a")))
return 0;
fprintf(stream, "\n");
}
/* Now we put some general information, commented */
fprintf(stream, "# tirific version 1\n");
fprintf(stream, "# logfile: %s\n", log -> logname);
if (fit -> fitmode >= GOLDEN_SECTION) {
fprintf(stream, "# fitmode was golden section or higher\n");
fprintf(stream, "# last acceptance was (1 accepted, 0 not accepted): %f\n", log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+ACCEPT_TABNR-1]);
}
else {
fprintf(stream, "# fitmode was metropolis\n");
}
/* The chisquare makes only sense in case of zero errors */
/* fprintf(stream, "# Chisquare: %f\n# Reduced Chisquare: %f\n", */
/* ftstab_get_colgrd((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+CHISQ_TABNR), */
/* ftstab_get_colgrd((NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+RCHISQ_TABNR)); */
fprintf(stream, "# Chisquare: %f\n# Reduced Chisquare: %f\n", tir_get_colgrd(log, rpm, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+CHISQ_TABNR), tir_get_colgrd(log, rpm, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+RCHISQ_TABNR));
/* We comment the header */
fprintf(stream, "# ");
/* We now compose a header entry for each keyword including radius */
for (i = 1; i <= (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i) {
/* Put the title */
ftstab_putcoltitl(key, i);
fprintf(stream, "%19s ", key);
sprintf(key2, "DELTA%s", key);
fprintf(stream, "%19s ", key2);
}
/* Now we include some specials */
sprintf(key, "RADI/kpc");
fprintf(stream, "%19s ", key);
sprintf(key2, "DELTA%s", key);
fprintf(stream, "%19s ", key2);
sprintf(key, "SBR/cm^(-2)");
fprintf(stream, "%19s ", key);
sprintf(key2, "DELTA%s", key);
fprintf(stream, "%19s ", key2);
sprintf(key, "SBR/(msol/(pc^2))");
fprintf(stream, "%19s ", key);
sprintf(key2, "DELTA%s", key);
fprintf(stream, "%19s ", key2);
sprintf(key, "WA_old (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "WA_new (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_ASC_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_ASC_DEC (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_DSC_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_DSC_DEC (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_APP_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_APP_DEC (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_REC_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_REC_DEC (deg)");
fprintf(stream, "%19s ", key);
fprintf(stream, "\n");
fprintf(stream, " ");
/* We read all values into the outarray */
tir_get_grid(log, rpm, log -> outarray);
for (j = 0; j < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++j)
rpm -> par[j] = log -> outarray[j];
/* We convert to internal units and interpolate over */
changetointern(rpm -> par, rpm -> nur, hdr, rpm -> ndisks);
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = chkchangep(fit -> varylist, fit -> fitmode, i, rpm -> nur);
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
interpover(rpm, rpm -> radsep, 0, NULL, fit -> index);
for (i = 0; i < 3; ++i) {
nvtot[i] = 0;
}
/* Now we calculate the direction of the total angular momentum of the observed component */
for (j = 0; j < rpm -> nr; ++j) {
/* We don't do a relativistic correction */
value = pow(rpm -> modpar[PRADI*rpm -> nr+j],2)*rpm -> modpar[PVROT*rpm -> nr+j]*rpm -> modpar[PSBR*rpm -> nr+j];
nvtot[0] = nvtot[0]+(double) value*sin(rpm -> modpar[PINCL*rpm -> nr+j])*sin(rpm -> modpar[PPA*rpm -> nr+j]);
nvtot[1] = nvtot[1]-(double) value*sin(rpm -> modpar[PINCL*rpm -> nr+j])*cos(rpm -> modpar[PPA*rpm -> nr+j]);
nvtot[2] = nvtot[2]+(double) value*cos(rpm -> modpar[PINCL*rpm -> nr+j]);
}
value = sqrt(pow(nvtot[0],2)+pow(nvtot[1],2)+pow(nvtot[2],2));
nvtot[0] = nvtot[0]/value;
nvtot[1] = nvtot[1]/value;
nvtot[2] = nvtot[2]/value;
/* Now get the normal vector of the reference ring */
nrefr[0] = sinf(rpm -> par[PINCL*rpm -> nur+rring-1])*sinf(rpm -> par[PPA*rpm -> nur+rring-1]);
nrefr[1] = -sinf(rpm -> par[PINCL*rpm -> nur+rring-1])*cosf(rpm -> par[PPA*rpm -> nur+rring-1]);
nrefr[2] = cosf(rpm -> par[PINCL*rpm -> nur+rring-1]);
/* Now we read in the values, we should have a third extension opened */
for (j = 1; j <= rpm -> nur; ++j) {
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS); ++i) {
/* Put the title */
value = tir_get_colgrd(log, rpm, i*rpm -> nur+j);
delta = tir_get_colrad(log, rpm, i*rpm -> nur+j);
fprintf(stream, "%+.12E %+.12E ", value, delta);
}
/* The single parameters */
for (i = 0; i < NSPARAMS; ++i) {
value = tir_get_colgrd(log, rpm, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+i+1);
delta = tir_get_colrad(log, rpm, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+i+1);
fprintf(stream, "%+.12E %+.12E ", value, delta);
}
/* Now the specials */
/* Calculate the radius in kpc */
value = tir_get_colgrd(log, rpm, PRADI*rpm -> nur+j);
delta = tir_get_colrad(log, rpm, PRADI*rpm -> nur+j);
/* Let's be slow, as this is only output */
value = value*1000*log -> distance*TWOPI/(360*60*60);
delta = delta*1000*log -> distance*TWOPI/(360*60*60);
fprintf(stream, "%+.12E %+.12E ", value, delta);
/* Calculate the approximate frequency */
vsys = tir_get_colgrd(log, rpm, PVSYS*rpm -> nur+j);
nu = (SPEEDOFLIGHT-vsys)*hdr -> rfreq/SPEEDOFLIGHT;
value = tir_get_colgrd(log, rpm, PSBR*rpm -> nur+j);
delta = tir_get_colrad(log, rpm, PSBR*rpm -> nur+j);
/* The intensity in the restframe scales like */
value = hdr -> itou*value*pow(hdr -> rfreq/nu,4);
delta = hdr -> itou*delta*pow(hdr -> rfreq/nu,4);
fprintf(stream, "%+.12E %+.12E ", value, delta);
/* Now we convert to Msol/pc^2 */
value = UTOSOLAR*value;
delta = UTOSOLAR*delta;
fprintf(stream, "%+.12E %+.12E ", value, delta);
fprintf(stream, " ");
/* Get the normal vector of the current ring */
nv[0] = sin(rpm -> par[PINCL*rpm -> nur+j-1])*sin(rpm -> par[PPA*rpm -> nur+j-1]);
nv[1] = -sin(rpm -> par[PINCL*rpm -> nur+j-1])*cos(rpm -> par[PPA*rpm -> nur+j-1]);
nv[2] = cos(rpm -> par[PINCL*rpm -> nur+j-1]);
/* Here is the scalar product with the reference ring */
value = nv[0]*nrefr[0]+nv[1]*nrefr[1]+nv[2]*nrefr[2];
/* This is the arcus */
value = value>1?0.0:RADTODEG*acos(value);
fprintf(stream, "%+.12E ", value);
/* Here is the scalar product with the reference frame */
value = nv[0]*nvtot[0]+nv[1]*nvtot[1]+nv[2]*nvtot[2];
/* This is the arcus */
value = value>1?0.0:RADTODEG*acos(value);
fprintf(stream, "%+.12E ", value);
/* LON and maximum velocity coordinates */
cosi = cos(rpm -> par[PINCL*rpm -> nur+j-1]);
sini = sin(rpm -> par[PINCL*rpm -> nur+j-1]);
cosp = cos(rpm -> par[PPA*rpm -> nur+j-1]);
sinp = sin(rpm -> par[PPA*rpm -> nur+j-1]);
/* Ascending LON */
/* Position */
posin[0] = 0;
posin[1] = rpm -> par[PRADI*rpm -> nur+j-1];
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Add central coordinates */
posout[0] = posout[0]+rpm -> par[PXPOS*rpm -> nur+j-1];
posout[1] = posout[1]+rpm -> par[PYPOS*rpm -> nur+j-1];
posout[2] = rpm -> par[PVSYS*rpm -> nur+j-1];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
/* Descending LON */
/* Position */
posin[0] = 0;
posin[1] = -rpm -> par[PRADI*rpm -> nur+j-1];
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Add central coordinates */
posout[0] = posout[0]+rpm -> par[PXPOS*rpm -> nur+j-1];
posout[1] = posout[1]+rpm -> par[PYPOS*rpm -> nur+j-1];
posout[2] = rpm -> par[PVSYS*rpm -> nur+j-1];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
/* Approaching Maximum Velocity */
/* Position */
posin[0] = -rpm -> par[PRADI*rpm -> nur+j-1];
posin[1] = 0;
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Add central coordinates */
posout[0] = posout[0]+rpm -> par[PXPOS*rpm -> nur+j-1];
posout[1] = posout[1]+rpm -> par[PYPOS*rpm -> nur+j-1];
posout[2] = rpm -> par[PVSYS*rpm -> nur+j-1];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
/* Receding Maximum Velocity */
/* Position */
posin[0] = rpm -> par[PRADI*rpm -> nur+j-1];
posin[1] = 0;
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Add central coordinates */
posout[0] = posout[0]+rpm -> par[PXPOS*rpm -> nur+j-1];
posout[1] = posout[1]+rpm -> par[PYPOS*rpm -> nur+j-1];
posout[2] = rpm -> par[PVSYS*rpm -> nur+j-1];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
fprintf(stream, "\n ");
}
fclose(stream);
return 1;
error:
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Writes an ascii table with the results */
static int writebigasctable(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
int def = 2;
int nel = 1;
int rring = 5;
int err = 1;
char mes[81];
FILE *stream;
int i, j;
/* char key[201]; */
char *key = NULL;
double value;
double vsys;
double nu;
double nv[3];
double nvtot[3];
double nrefr[3];
double cosp;
double sinp;
double sini;
double cosi;
double pp[3];
double posin[3];
double posout[3];
char **varystr = NULL;
int keypres, nread, nreturned;
if ((key)) {
free(key);
key = NULL;
}
if (varystr) {
freeparsed(varystr);
varystr = NULL;
}
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "BIGTABLE", "Give big table name.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(key = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(key = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* If there is no input we stop here */
if (*key == '\0') {
free(key);
return 1;
}
/* Check if there was a logfile and stop if there wasn't */
/* if (*log -> logname == '\0') */
/* return 0; */
/* Get the reference ring */
sprintf(mes, "Give reference ring for warp angle calculation");
while ((err)) {
userint_tir(startinfv -> arel, &rring, &nel, &def, "REFRING=", mes);
if (rring <= 0 || rring > rpm -> nur) {
sprintf(mes, "REFRING: impossible number");
cancel_tir(startinfv -> arel, "REFRING=", 2);
def = 4;
}
else
err = 0;
}
/* Try to open the output file */
if (!(stream = fopen(key, "r"))) {
/* If the file doesn't exist we compose a header */
if (!(stream = fopen(key, "w"))) {
return 0;
}
}
else {
if (!(stream = fopen(key, "a")))
return 0;
fprintf(stream, "\n");
}
/* Now we put some general information, commented */
fprintf(stream, "# tirific version 1\n");
fprintf(stream, "# logfile: %s\n", log -> logname);
if (fit -> fitmode >= GOLDEN_SECTION) {
fprintf(stream, "# fitmode was golden section\n");
fprintf(stream, "# last acceptance was (1 accepted, 0 not accepted): %f\n", log -> outarray[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+ACCEPT_TABNR-1]);
}
else {
fprintf(stream, "# fitmode was metropolis\n");
}
/* The chisquare makes only sense in case of zero errors */
if (tir_get_colrad(log, rpm, (PRADI)*rpm -> nur+1) == 0.0) {
fprintf(stream, "# Chisquare: %f\n# Reduced Chisquare: %f\n", tir_get_colgrd(log, rpm, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+CHISQ_TABNR), tir_get_colgrd(log, rpm, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+NSPARAMS+RCHISQ_TABNR));
}
/* We comment the header */
fprintf(stream, "# ");
/* We now compose a header entry for each keyword including radius */
for (i = 1; i <= (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i) {
/* Put the title */
ftstab_putcoltitl(key, i);
fprintf(stream, "%19s ", key);
}
/* Now we include some specials */
sprintf(key, "RADI/kpc");
fprintf(stream, "%19s ", key);
sprintf(key, "SBR/cm^(-2)");
fprintf(stream, "%19s ", key);
sprintf(key, "SBR/(msol/(pc^2))");
fprintf(stream, "%19s ", key);
sprintf(key, "WA_old (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "WA_new (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_ASC_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_ASC_DEC (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_DSC_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LON_DSC_DEC (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_APP_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_APP_DEC (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_REC_RA (deg)");
fprintf(stream, "%19s ", key);
sprintf(key, "LMV_REC_DEC (deg)");
fprintf(stream, "%19s ", key);
fprintf(stream, "\n");
fprintf(stream, " ");
/* We read all values into the par array */
tir_get_grid(log, rpm, log -> outarray);
for (j = 0; j < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++j)
rpm -> par[j] = log -> outarray[j];
/* We con't convert to internal units and interpolate over */
/* changetointern(rpm -> par, rpm -> nur, hdr, rpm -> ndisks); */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
interpover(rpm, dinterntoparam(rpm -> radsep, RADI, hdr, rpm -> ndisks), 0, NULL, fit -> index);
for (i = 0; i < 3; ++i) {
nvtot[i] = 0;
}
/* Now we calculate the direction of the total angular momentum of the observed component */
for (j = 0; j < rpm -> nr; ++j) {
/* We don't do a relativistic correction for this */
value = pow(rpm -> modpar[PRADI*rpm -> nr+j],2)*rpm -> modpar[PVROT*rpm -> nr+j]*rpm -> modpar[PSBR*rpm -> nr+j];
nvtot[0] = nvtot[0]+(double) value*sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*sin(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nvtot[1] = nvtot[1]-(double) value*sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*cos(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nvtot[2] = nvtot[2]+(double) value*cos(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j]);
}
value = sqrt(pow(nvtot[0],2)+pow(nvtot[1],2)+pow(nvtot[2],2));
nvtot[0] = nvtot[0]/value;
nvtot[1] = nvtot[1]/value;
nvtot[2] = nvtot[2]/value;
/* Now get the normal vector of the reference ring */
nrefr[0] = sinf(DEGTORAD*rpm -> par[PINCL*rpm -> nur+rring-1])*sinf(DEGTORAD*rpm -> par[PPA*rpm -> nur+rring-1]);
nrefr[1] = -sinf(DEGTORAD*rpm -> par[PINCL*rpm -> nur+rring-1])*cosf(DEGTORAD*rpm -> par[PPA*rpm -> nur+rring-1]);
nrefr[2] = cosf(DEGTORAD*rpm -> par[PINCL*rpm -> nur+rring-1]);
/* Now we read in the values */
for (j = 0; j < rpm -> nr; ++j) {
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS); ++i) {
value = rpm -> modpar[i*rpm -> nr+j];
fprintf(stream, "%+.12E ", value);
}
/* The single parameters */
for (i = 0; i < NSPARAMS; ++i) {
value = tir_get_colgrd(log, rpm, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+i+1);
fprintf(stream, "%+.12E ", value);
}
/* Now the specials */
/* Calculate the radius in kpc */
value = rpm -> modpar[PRADI*rpm -> nr+j];
/* Let's be slow, as this is only output */
value = value*1000*log -> distance*TWOPI/(360*60*60);
fprintf(stream, "%+.12E ", value);
/* Calculate the approximate frequency */
vsys = rpm -> modpar[PVSYS*rpm -> nr+j];
nu = (SPEEDOFLIGHT-vsys)*hdr -> rfreq/SPEEDOFLIGHT;
value = rpm -> modpar[PSBR*rpm -> nr+j];
/* The intensity in the restframe scales like */
value = hdr -> itou*value*pow(hdr -> rfreq/nu,4);
fprintf(stream, "%+.12E ", value);
/* Now we convert to Msol/pc^2 */
value = UTOSOLAR*value;
fprintf(stream, "%+.12E ", value);
/* Get the normal vector of the current ring */
nv[0] = sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*sin(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nv[1] = -sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*cos(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nv[2] = cos(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j]);
/* Here is the scalar product with the reference ring */
value = nv[0]*nrefr[0]+nv[1]*nrefr[1]+nv[2]*nrefr[2];
/* This is the arcus */
value = value>1?0.0:RADTODEG*acos(value);
fprintf(stream, "%+.12E ", value);
/* Here is the scalar product with the reference frame */
value = nv[0]*nvtot[0]+nv[1]*nvtot[1]+nv[2]*nvtot[2];
/* This is the arcus */
value = value>1?0.0:RADTODEG*acos(value);
fprintf(stream, "%+.12E ", value);
/* LON and maximum velocity coordinates */
cosi = cos(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j]);
sini = sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j]);
cosp = cos(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
sinp = sin(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
/* Ascending LON */
/* Position */
posin[0] = 0;
posin[1] = dparamtointern(rpm -> modpar[PRADI*rpm -> nr+j], RADI, hdr, rpm -> ndisks);
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Get central coordinates */
posin[0] = rpm -> modpar[PXPOS*rpm -> nr+j];
posin[1] = rpm -> modpar[PYPOS*rpm -> nr+j];
posin[2] = rpm -> modpar[PVSYS*rpm -> nr+j];
globtointern(posin, pp, hdr);
/* Add central coordinates */
posout[0] = posout[0]+pp[0];
posout[1] = posout[1]+pp[1];
posout[2] = pp[2];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
/* Descending LON */
/* Position */
posin[0] = 0;
posin[1] = -dparamtointern(rpm -> modpar[PRADI*rpm -> nr+j], RADI, hdr, rpm -> ndisks);
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Get central coordinates */
posin[0] = rpm -> modpar[PXPOS*rpm -> nr+j];
posin[1] = rpm -> modpar[PYPOS*rpm -> nr+j];
posin[2] = rpm -> modpar[PVSYS*rpm -> nr+j];
globtointern(posin, pp, hdr);
/* Add central coordinates */
posout[0] = posout[0]+pp[0];
posout[1] = posout[1]+pp[1];
posout[2] = pp[2];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
/* Approaching Maximum Velocity */
posin[0] = -dparamtointern(rpm -> modpar[PRADI*rpm -> nr+j], RADI, hdr, rpm -> ndisks);;
posin[1] = 0;
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Get central coordinates */
posin[0] = rpm -> modpar[PXPOS*rpm -> nr+j];
posin[1] = rpm -> modpar[PYPOS*rpm -> nr+j];
posin[2] = rpm -> modpar[PVSYS*rpm -> nr+j];
globtointern(posin, pp, hdr);
/* Add central coordinates */
posout[0] = posout[0]+pp[0];
posout[1] = posout[1]+pp[1];
posout[2] = pp[2];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
/* Receding Maximum Velocity */
posin[0] = dparamtointern(rpm -> modpar[PRADI*rpm -> nr+j], RADI, hdr, rpm -> ndisks);;
posin[1] = 0;
posin[2] = 0;
/* Velocity will not be regarded*/
/* Rotate about x-axis */
maths_rotax(cosi, sini, posin, pp);
/* Rotate about z-axis */
maths_rotaz(cosp, sinp, pp, posout);
/* Get central coordinates */
posin[0] = rpm -> modpar[PXPOS*rpm -> nr+j];
posin[1] = rpm -> modpar[PYPOS*rpm -> nr+j];
posin[2] = rpm -> modpar[PVSYS*rpm -> nr+j];
globtointern(posin, pp, hdr);
/* Add central coordinates */
posout[0] = posout[0]+pp[0];
posout[1] = posout[1]+pp[1];
posout[2] = pp[2];
/* Change into user coordinates */
interntoglob(posout, pp, hdr);
/* Print */
fprintf(stream, "%+.12E ", pp[0]);
fprintf(stream, "%+.12E ", pp[1]);
fprintf(stream, "\n ");
}
fclose(stream);
/* Finally */
if ((key))
free(key);
if ((varystr))
freeparsed(varystr);
return 1;
error:
/* Strangely, for this function, 0 returned means error. This is an old functino... */
if ((key))
free(key);
if ((varystr))
freeparsed(varystr);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Make a qfits header suitable for coolgal output */
static qfits_header *makecoolhdr(hdrinf *hdr, double beamsizeindeg)
{
/* char key[9]; */
char value[21];
/* int j; */
/* int level = 0; */
/* int err = 0; */
int sizez;
qfits_header *header = NULL;
/* The bitpix is -32 */
if (!(header = ftsout_putcard(header, "BITPIX","-32")))
goto error;
/* The number of axes is set to three */
if (!ftsout_putcard(header, "NAXIS","3"))
goto error;
/* Now get the axis numbers */
sprintf(value, "%i", hdr -> bsize1*hdr->coolbin);
if (!ftsout_putcard(header, "NAXIS1",value))
goto error;
sprintf(value, "%i", hdr -> bsize2*hdr->coolbin);
if (!ftsout_putcard(header, "NAXIS2",value))
goto error;
/* The third axis is simply the maximum spatial size */
sprintf(value, "%i", sizez = ((hdr -> bsize2 > hdr -> bsize1)?hdr -> bsize2:hdr -> bsize1)*hdr->coolbin);
if (!ftsout_putcard(header, "NAXIS3",value))
goto error;
/* May contain an extension */
if (!ftsout_putcard(header, "EXTEND","T"))
goto error;
/* These are clear */
if (!ftsout_putcard(header, "BSCALE","1"))
goto error;
if (!ftsout_putcard(header, "BZERO","0"))
goto error;
/* The bunit is Jy*km/s/beam, while this is the 3d beam */
if (!ftsout_putcard(header, "BUNIT","'JY*(KM/S)/BEAM'"))
goto error;
/* The cdelt is taken from the hdr struct, this should be ok with the unit being DEGREE*/
sprintf(value, "%.12E", hdr -> userglobcdelt[0]/((double) hdr -> coolbin));
if (!ftsout_putcard(header, "CDELT1", value))
goto error;
/* The crpix is copied from the header of the inset */
sprintf(value, "%.12E", hdr -> setcrpix[0]*((double) hdr -> coolbin));
if (!ftsout_putcard(header, "CRPIX1", value))
goto error;
/* The crval in user units -> degree */
sprintf(value, "%.12E", hdr -> userglobcrval[0]);
if (!ftsout_putcard(header, "CRVAL1", value))
goto error;
/* This is nasty, because we have to re-read the info */
/* sprintf(key, "CTYPE%i", hdr -> inaxperm[0]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* gdsd_rchar_tir(hdr -> inset, key, &(level), value, &err); */
/* Type */
if (!ftsout_putcard(header, "CTYPE1", hdr -> oric -> type_x))
goto error;
/* if (!ftsout_putcard(header, "CUNIT1", "'DEGREE '")) */
/* goto error; */
/* The cdelt is taken from the hdr struct, this should be ok with the unit being DEGREE*/
sprintf(value, "%.12E", hdr -> userglobcdelt[1]/((double) hdr -> coolbin));
if (!ftsout_putcard(header, "CDELT2", value))
goto error;
/* The crpix is copied from the header of the inset */
sprintf(value, "%.12E", hdr -> setcrpix[1]*((double) hdr -> coolbin));
if (!ftsout_putcard(header, "CRPIX2", value))
goto error;
/* The crval in user units -> degree */
sprintf(value, "%.12E", hdr -> userglobcrval[1]);
if (!ftsout_putcard(header, "CRVAL2", value))
goto error;
/* This is nasty, because we have to re-read the info */
/* sprintf(key, "CTYPE%i", hdr -> inaxperm[1]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* gdsd_rchar_tir(hdr -> inset, key, &(level), value, &err); */
if (!ftsout_putcard(header, "CTYPE2", hdr -> oric -> type_y))
goto error;
/* if (!ftsout_putcard(header, "CUNIT2", "'DEGREE '")) */
/* goto error; */
if (!ftsout_putcard(header, "EPOCH", hdr -> oric -> epoch))
goto error;
/* The third axis is the artificial one */
/* The cdelt is copied from the inset */
sprintf(value, "%.12E", fabs(hdr -> userglobcdelt[0])/((double) hdr -> coolbin));
if (!ftsout_putcard(header, "CDELT3", value))
goto error;
/* crpix is in the middle */
sprintf(value, "%.12E", ((double) sizez)/2.0);
if (!ftsout_putcard(header, "CRPIX3", value))
goto error;
/* This is exactly 0 */
if (!ftsout_putcard(header, "CRVAL3", "0.0"))
goto error;
/* The type is somthing without projection, this should do */
if (!ftsout_putcard(header, "CTYPE3", "'ANGLE '"))
goto error;
/* This is DEGREE again */
/* if (!ftsout_putcard(header, "CUNIT3", "'DEGREE '")) */
/* goto error; */
/* Fourth axis is velocity, one pixel with the width of the whole cube to give plotting programs an orientation */
/* if (!ftsout_putcard(header, "CDELT4", "1.0")) */
/* goto error; */
/* if (!ftsout_putcard(header, "CRPIX4", "1.0")) */
/* goto error; */
/* if (!ftsout_putcard(header, "CRVAL4", "0.0")) */
/* goto error; */
/* if (!ftsout_putcard(header, "CTYPE4", "' '")) */
/* goto error; */
/* if (!ftsout_putcard(header, "CUNIT4", "'Y'")) */
/* goto error; */
/* Now we just put the beam properties, symmetric beam */
sprintf(value, "%.12E", beamsizeindeg);
if (!ftsout_putcard(header, "BMAJ", value))
goto error;
sprintf(value, "%.12E", beamsizeindeg);
if (!ftsout_putcard(header, "BMIN", value))
goto error;
if (!ftsout_putcard(header, "BPA", "0"))
goto error;
return header;
error:
if ((header))
ftsout_header_destroy(header);
header = NULL;
return header;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Produces a 3d fits image of the model */
static int coolgal(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
int i;
char *coolname = NULL;
char mes[81];
int def;
int nel;
int err;
qfits_header *header;
Cube thecube;
double beam;
float *expfcs;
float sincosofangle[2];
char **varystr = NULL;
int keypres, nread, nreturned;
/* First check if the user wants a coolgal output */
/* sprintf(mes, "Give cool name."); */
/* for (i = 0; i < 200; ++i) */
/* coolname[i] = ' '; */
/* coolname[200] = '\0'; */
/* def = 2; */
/* nel = 1; */
/* userchar_tir(coolname, &nel, &def, "COOLGAL=", mes); */
/* termsinglestr(coolname); */
/* cancel_tir(startinfv -> arel, "COOLGAL"); */
if ((coolname)) {
free(coolname);
coolname = NULL;
}
if (varystr) {
freeparsed(varystr);
varystr = NULL;
}
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "COOLGALPAST", "Give cool name.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(coolname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(coolname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* The default is to do nothing */
if (*coolname == '\0') {
free(coolname);
return 1;
}
/* Now ask if the user wants a specific kind of beam, the default being the max beam */
sprintf(mes, "Give 3d beam size (arcsec)");
beam = hdr -> deltgridtouser[0]*((double) hdr -> bmaj);
def = 2;
nel = 1;
err = 1;
beam = 10;
while((err)) {
userdble_tir(startinfv -> arel, &beam, &nel, &def, "COOLBEAM=", mes);
if (beam >= 0.0) {
err = 0;
}
else {
sprintf(mes, "COOLBEAM should be >= 0");
cancel_tir(startinfv -> arel, "COOLBEAM=", 2);
beam = hdr -> deltgridtouser[0]*((double) hdr -> bmaj);
def = 1;
}
}
/* Transfer the beam into deg */
beam = hdr -> globgridtouser[0]*beam/hdr -> deltgridtouser[0];
/* Make a header, if the beam is 0, we normalise everything such that the units get right */
if (!(header = makecoolhdr(hdr, ((beam))?beam:sqrt(TWOPI)/(hdr -> globgridtouser[0]*0.42466090014401))))
return 1;
/* Transfer the beam back to grid units */
beam = beam/hdr -> globgridtouser[0];
/* Now arrange the cube */
thecube.refpix_x = 0;
thecube.refpix_y = 0;
thecube.refpix_v = 0;
thecube.size_x = hdr -> bsize1;
thecube.size_y = hdr -> bsize2;
thecube.size_v = (thecube.size_x > thecube.size_y)?thecube.size_x:thecube.size_y;
thecube.scale = 1.0;
thecube.padding = 0;
/* After that, we can deallocate to get some memory, but first I try
not to do so and see how that works. */
/* We read in the values, this should be possible and make sense */
tir_get_grid(log, rpm, log -> outarray);
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i)
rpm -> par[i] = log -> outarray[i];
/* Convert the read parameter list to internal units */
changetointern(rpm -> par, rpm -> nur, hdr, rpm -> ndisks);
/* provide some info */
nel=1;
sprintf(mes, "cool number of bytes used: %lu", thecube.size_x*thecube.size_y*thecube.size_v*sizeof(float));
anyout_tir(&nel, mes);
/* Now we allocate the cube, not caring for the padding, this will be done automatically */
if (!(thecube.points = (float *) malloc(thecube.size_x*thecube.size_y*thecube.size_v*sizeof(float)))) {
ftsout_header_destroy(header);
return 1;
}
/* Make the cube */
makecoolpoints(&thecube, hdr, rpm, fit);
/* Convolve it */
sincosofangle[0] = 0;
sincosofangle[1] = 1;
if (!(expfcs = expofacsfft(0.42466090014401*beam, 0.42466090014401*beam, 0.42466090014401*beam, sincosofangle))) {
ftsout_header_destroy(header);
free(thecube.points);
return 1;
}
/* Now, the normalisation is the fifth factor, we multiply it with this */
expfcs[4] = expfcs[4]*sqrtf(TWOPI)*0.42466090014401*beam;
/* This is the actual convolution */
if ((beam)) {
convolgaussfft(&thecube, expfcs);
}
/* Output it */
ftsout_writecube(coolname, &thecube, header);
/* Deallocate everything */
ftsout_header_destroy(header);
free(thecube.points);
free(expfcs);
/* Finally */
if ((coolname))
free(coolname);
if ((varystr))
freeparsed(varystr);
return 1;
error:
/* Strangely, for this function, 0 returned means error. This is an old functino... */
if ((coolname))
free(coolname);
if ((varystr))
freeparsed(varystr);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Makes a 3d pointsource model and packs in on cube */
static int makecoolpoints(Cube *cube, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
int i,j,k;
float ringflux; /* Total flux of a subring */
int nc; /* Cloudnumber of a subring */
float cfluxcorr; /* The correct flux of a pointsource */
float sininc;
float cosinc;
float sinpa;
float cospa;
float r; /* A radius */
float az; /* Azimuth of pointsource */
float cosaz; /* The cosine of the az (memory wasting) */
float sinaz; /* The sine of the az (memory wasting) */
int grid[3]; /* Grid positions */
int totflux = 0;
float z0; /* The central plane for the z */
float pp[6]; /* Cartesian coordinates in phase-space, x,y,z,vx,vy,vz */
/* x: DEC, y: LOS, z: RA */
float pp2[6]; /* Cartesian coordinates in phase-space, x,y,z,vx,vy,vz */
int disk;
z0 = ((float) cube -> size_v)/2;
interpover(rpm, rpm -> radsep, 0, NULL, fit -> index);
/* Initialise the model array */
cuberase(cube);
for (disk = 0; disk < rpm -> ndisks; ++disk) {
/* Do all the loops */
for (i = 0; i < rpm -> nr; ++i) {
/* Calculate the ringflux */
ringflux = TWOPI*rpm -> modpar[PRADI*rpm -> nr+i]*rpm -> radsep*rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*rpm -> nr+i];
/* Calculate the cloudnumber, rounded down, Kamphuis bugfix */
nc = (int) (ringflux/rpm -> cflux[disk]);
/* We decide to change the cloudflux a bit instead of accepting an error in the ringflux */
cfluxcorr = ringflux/nc;
if (nc > 0) {
/* We calculate cos's and sins and reset the random number generator */
sininc=sinf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nr+i]);
cosinc=cosf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nr+i]);;
sinpa=sinf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PPA)*rpm -> nr+i]);
cospa=cosf(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PPA)*rpm -> nr+i]);
rpm -> sd[disk][i].iseed2[1] = i;
maths_rndmf_init(rpm -> sd[disk][i].iseed2, rpm -> sd[disk][i].permrandstr);
/* reset the zprof */
zprof(6, rpm -> sd[disk][i].permrandstr, &(rpm -> sd[disk][i].y2));
/* now create the clouds and grid them */
for (j = 0; j < nc; ++j) {
/* The probability for the #radius is weighted by r, and this is no approximation */
r = sqrtf((rpm -> modpar[PRADI*rpm -> nr+i]-0.5*rpm -> radsep)*(rpm -> modpar[PRADI*rpm -> nr+i]-0.5*rpm -> radsep)+2*rpm -> radsep*rpm -> modpar[PRADI*rpm -> nr+i]*maths_rndmf(rpm -> sd[disk][i].permrandstr));
/* Azimuth is easy */
az = TWOPI*maths_rndmf(rpm -> sd[disk][i].permrandstr);
cosaz = cosf(az);
sinaz = sinf(az);
/* Now, these are the cartesian coordinates, if you look face-on at the ring in the system of the ring, x eastwards, y to the north, z along los from you to the source */
/* x = cosaz*r; */
/* y = sinaz*r; */
/* z = zprof(ltype)*modpar[PZ0*rpm -> nr+i]; */
/* vx = -sinaz*modpar[PVROT*rpm -> nr+i]; */
/* vy = cosaz*modpar[PVROT*rpm -> nr+i]; */
/* vz = 0; */
/* Now, the whole system will be rotated about the x-axis with the amount of the inclination */
/* xp = x; */
/* yp = cosinc*y-sininc*z; */
/* zp = sininc*y+cosinc*z; */
/* vxp = vx; */
/* vyp = cosinc*vy-sininc*vz; */
/* vzp = sininc*vy+cosinc*vz; */
/* Now we rotate about the z-axis with pa, because in this module the pa is defined as the angle with the minor axis */
/* x = xp*cos(-pa)-yp*sin(-pa) or x = xp*cospa-yp*sinpa; */
/* y = xp*sin(-pa)+yp*cos(-pa) or y = xp*sinpa+yp*cospa; */
/* z = zp; or z = zp; */
/* vx = vxp*cos(-pa)-vyp*sin(-pa) or vx = vxp*cospa-vyp*sinpa; */
/* vy = vxp*sin(-pa)+vyp*cos(-pa) or vy = vxp*sinpa+vyp*cospa; */
/* vz = vzp; or vz = vzp; */
/* z = zprof(rpm -> ltype[0], rpm -> permrandstr)*rpm -> modpar[PZ0*rpm -> nr+i]; */
/* x = (cosaz*r)*cospa-(cosinc*(sinaz*r)-sininc*z)*sinpa; */
/* y = (cosaz*r)*sinpa+(cosinc*(sinaz*r)-sininc*z)*cospa; */
/* Instead of vz this is the z component in the middle of the cube */
/* z = sininc*sinaz*r+cosinc*z; */
/* vz = (sininc*cosaz*rpm -> modpar[PVROT*rpm -> nr+i]); */
/* Calculate the coordinates of the point source before rotation */
pp[0] = cosaz*r;
pp[1] = sinaz*r;
pp[2] = zprof(rpm -> ltype[disk], rpm -> sd[disk][i].permrandstr, &(rpm -> sd[disk][i].y2))*rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PZ0)*rpm -> nr+i];
(*(rpm -> inf_wm1v[disk] -> prs))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm2v[disk] -> prs))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm3v[disk] -> prs))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm4v[disk] -> prs))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm1v[disk] -> prc))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm2v[disk] -> prc))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm3v[disk] -> prc))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm4v[disk] -> prc))((void *) rpm, pp+2, i, sinaz, cosaz, disk);
(*(rpm -> inf_wm0v[disk] -> pr)) ((void *) rpm, pp+2, i, sinaz, cosaz, disk);
/* Now rotate about the x-axis by i */
pp2[0] = pp[0];
pp2[1] = pp[1]*cosinc-pp[2]*sininc;
pp2[2] = pp[1]*sininc+pp[2]*cosinc;
/* Now we shift */
(*(rpm -> inf_lc0v[disk] -> pr))((void *) rpm, pp2+0, i, sinaz, cosaz, disk);
(*(rpm -> inf_ls0v[disk] -> pr))((void *) rpm, pp2+1, i, sinaz, cosaz, disk);
/* Now rotate about the z-axis by pa */
pp[0] = pp2[0]*cospa-pp2[1]*sinpa;
pp[1] = pp2[0]*sinpa+pp2[1]*cospa;
pp[2] = pp2[2];
/* Here's the shortcut version */
/* pp[0] = pp2[0]*cospa-pp2[1]*sinpa; */
/* pp[1] = pp2[0]*sinpa+pp2[1]*cospa; */
/* pp[2] = pp[1]*sininc+pp[2]*cosinc; */
/* of course we could make it even shorter, but we'll leave it at that. Next thingy is to grid the pointsource */
grid[0] = roundnormal(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nr+i]-pp[1]);
if (grid[0] >= 0 && grid[0] < cube -> size_x) {
grid[1] = roundnormal(rpm -> modpar[(PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nr+i]+pp[0]);
if (grid[1] >= 0 && grid[1] < cube -> size_y) {
/* For the sake of clearity, we kill the subsnuma operation in the source, in principle thus allowing only for the radio convention for velocity, but gaining an understanding of the code. What is seen here should not be done. It's really not what anyone should wish for. */
grid[2] = roundnormal((z0-pp[2]));
if (grid[2] >= 0 && grid[2] < cube -> size_v) {
++totflux;
/* This is the position in the linear cube array */
k = grid[0]+ cube -> size_x*(grid[1]+cube -> size_y*grid[2]);
cube -> points[k] = cube -> points[k]+cfluxcorr;
}
}
}
}
}
}
}
/* We return the number of clouds */
return totflux;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Produces a progress file at every ring loop and write the last line. Kamphuis addition */
static int progressout(startinf *startinfv, char *message)
{
/* int i; */
/* int def = 2; */
/* int nel = 1; */
FILE *stream;
char *progname = NULL;
/* int obsint = 0;
char obsmes[180];*/
/* char mes[100]; */
char *currentname;
char **varystr = NULL;
int keypres, nread, nreturned;
/* for (i = 0; i < 200; ++i) { */
/* progname[i] = ' '; */
/* } */
/* progname[200] = '\0'; */
/* Ask the user what to do */
/* sprintf(mes, "Give a progress file name for no point actually when you can read this"); */
/* userchar_tir(progname, &nel, &def, "PROGRESSLOG=", mes); */
/* termsinglestr(progname); */
/* cancel_tir(startinfv -> arel, "PROGRESSLOG"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "PROGRESSLOG", "Give a progress file name for no point actually when you can read this.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(progname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(progname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* i = 0; */
currentname = progname;
if (*currentname != '\0') {
/* Try to open the output, we overwrite */
if (!(stream = fopen(currentname, "w")))
goto error;
/* Now put the first line, copy from input */
fprintf(stream,"%s",message);
fprintf(stream, "\n");
/* and close again otherwise the file stays unreadable */
fflush(stream);
fclose(stream);
fflush(NULL);
}
if ((progname))
free(progname);
if ((varystr))
freeparsed(varystr);
return 0;
error:
if ((progname))
free(progname);
if ((varystr))
freeparsed(varystr);
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Appends a message to the progress file at the end of the fitting procedure. Kamphuis addition */
static int progressfinished(startinf *startinfv)
{
/* int i; */
/* int def = 2; */
/* int nel = 1; */
FILE *stream;
char *progname = NULL;
/* int obsint = 0;
char obsmes[180];*/
/* char mes[100]; */
char *currentname;
char **varystr = NULL;
int keypres, nread, nreturned;
/* for (i = 0; i < 200; ++i) { */
/* progname[i] = ' '; */
/* } */
/* progname[200] = '\0'; */
/* Ask the user what to do */
/* sprintf(mes, "Give a progress file name for no point actually when you can read this"); */
/* userchar_tir(progname, &nel, &def, "PROGRESSLOG=", mes); */
/* termsinglestr(progname); */
/* i = 0; */
/* cancel_tir(startinfv -> arel, "PROGRESSLOG"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "PROGRESSLOG", "Give a progress file name for no point actually when you can read this.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(progname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(progname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
currentname = progname;
if (*currentname != '\0') {
/* Try to open the output, we append */
if (!(stream = fopen(currentname, "a")))
goto error;
/* Now put the first line, copy from input */
fprintf(stream,"<STATUS> Tirific Finished");
fprintf(stream, "\n");
/* and close again otherwise the file stays unreadable */
fclose(stream);
}
if ((progname))
free(progname);
if ((varystr))
freeparsed(varystr);
return 1;
error:
if ((progname))
free(progname);
if ((varystr))
freeparsed(varystr);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Produces one or two tirific logfiles containing the results */
static int tirout(startinf *startinfv, loginf *log, ringparms *rpm, fitparms *fit, int nrplts)
{
int i, j, k, l, m, n;
int def = 2;
int nel = 1;
int acc;
int len;
char *defname = NULL;
char *deintername = NULL;
char key[9];
char *currentname;
char mes[81];
FILE *stream;
/* char input[VARYHSTRELES]; */ /* Has the length of the maximum input */
char format[8];
char format2[8];
/* double *smarray = NULL; */
double *reparray = NULL;
double smsum, smweightsum, weight, lm1;
char inqstr[13];
int nrings;
int ringnr;
double *radii = NULL;
int givrad;
double dpdr;
int disk;
char placer[10];
char **varystr = NULL;
int keypres, nread, nreturned;
time_t restimest = 0;
/* Initialise the input arrays */
/* for (i = 0; i < 200; ++i) { */
/* defname[i] = ' '; */
/* deintername[i] = ' '; */
/* } */
/* defname[200] = '\0'; */
/* deintername[200] = '\0'; */
/* Ask the user what to do */
/* sprintf(mes, "Give a .def file name for best results output"); */
/* userchar_tir(defname, &nel, &def, "TIRDEF=", mes); */
/* termsinglestr(defname); */
/* sprintf(mes, "Give a file name for smoothed results output"); */
/* userchar_tir(deintername, &nel, &def, "TIRSMO=", mes); */
/* termsinglestr(deintername); */
/* cancel_tir(startinfv -> arel, "TIRDEF"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "TIRDEF", "Give a progress file name for no point actually when you can read this.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(defname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(defname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* cancel_tir(startinfv -> arel, "TIRSMO"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "TIRSMO", "Give a progress file name for no point actually when you can read this.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(deintername = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(deintername = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
sprintf(mes, "Give accuracy of def file output [2]");
i = 1;
acc = 5;
def = 2;
while ((i)) {
userint_tir(startinfv -> arel, &acc, &nel, &def, "TIRACC=", mes);
if (acc < 1 || acc > 99) {
sprintf(mes, "TIRACC: Must be larger than 0");
def = 4;
cancel_tir(startinfv -> arel, "TIRACC=", 2);
}
else
--i;
}
def = 2;
if (*deintername != '\0') {
/* Smoothing kernel is a Hanning function h(k) = (Sum_l =
-(len-1)/2, ..., (len-1)/2
f(k+l)*(1+cos(2pi*l/(len-1))))/(Sum_l = -(len-1)/2, ...,
(len-1)/2 (1+cos(2pi*l/(len-1)))), while the at the edges the
function plus weights are evaluated only where defined */
sprintf(mes, "Give length of smoothing kernel [5]");
i = 1;
len = 5;
while ((i)) {
userint_tir(startinfv -> arel, &len, &nel, &def, "TIRLEN=", mes);
if (len < 2 || len > 99) {
sprintf(mes, "TIRLEN: Must be larger than 1");
def = 4;
cancel_tir(startinfv -> arel, "TIRLEN=", 2);
}
else if ((float) (len/2) == ((float) len) / 2.) {
sprintf(mes, "TIRLEN: Must be odd %f %f", ((float) (len/2)), (((float) len) / 2.) );
def = 4;
cancel_tir(startinfv -> arel, "TIRLEN=", 2);
}
else
--i;
}
/* Allocate the array for smoothing */
/* if (!(smarray = (double *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(double)))) */
/* goto error; */
}
/* Query the number of rings */
sprintf(mes, "Give number of rings [%i]", rpm -> nur);
i = 1;
def = 2;
nel = 1;
nrings = rpm -> nur;
while ((i)) {
userint_tir(startinfv -> arel, &nrings, &nel, &def, "TIRNR=", mes);
if (nrings < 2) {
sprintf(mes, "TIRNR: Must be larger than 1");
def = 4;
cancel_tir(startinfv -> arel, "TIRNR=", 2);
}
else
--i;
}
/* Now allocate the radius array */
if (!(radii = (double *) malloc(nrings*sizeof(double))))
goto error;
/* We read all values into the outarray */
tir_get_grid(log, rpm, log -> outarray);
/* BUGFIX: We copy that to the par array */
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i){
rpm -> par[i] = log -> outarray[i];
}
/* Now ask the user to give the radii */
sprintf(mes, "Give radii");
i = 1;
def = 2;
nel = nrings;
while ((i)) {
/* Fill it with the old values */
for (ringnr = 0; (ringnr < nrings) && (ringnr < rpm -> nur); ++ringnr) {
radii[ringnr] = rpm -> par[PRADI*rpm -> nur+ringnr];
}
/* Fill the rest, extrapolating with the last stepwidth, this should work */
while (ringnr < nrings) {
radii[ringnr] = 2*radii[ringnr-1]-radii[ringnr-2];
++ringnr;
}
/* Check if we can interpolate */
givrad = userdble_tir(startinfv -> arel, radii, &nel, &def, "TIRRAD=", mes);
if ((givrad < 2) && (givrad != 0)) {
sprintf(mes, "TIRRAD: give more than 1 element");
def = 4;
cancel_tir(startinfv -> arel, "TIRRAD=", 2);
}
else {
/* Check the first radius */
if (radii[0] != 0.0) {
sprintf(mes, "TIRRAD: First radius has to be 0.0");
def = 4;
cancel_tir(startinfv -> arel, "TIRRAD=", 2);
}
else {
/* Extrapolate */
if ((givrad))
while (givrad < nrings) {
radii[givrad] = 2*radii[givrad-1]-radii[givrad-2];
++givrad;
}
/* Check if the radii are in ascending order */
for (ringnr = 1; ringnr < nrings; ++ringnr) {
if (radii[ringnr] <= radii[ringnr-1]) {
i = 2;
break;
}
}
if (i == 2) {
sprintf(mes, "TIRRAD: Radii must be in ascending order %i %f %f %f", ringnr, radii[ringnr], radii[ringnr-1], radii[ringnr-2]);
def = 4;
i = 1;
cancel_tir(startinfv -> arel, "TIRRAD=", 2);
}
else
i = 0;
}
}
}
/* Now we should have a proper array with radii */
/* Construct the format strings, a bit tricky */
*format = '%';
sprintf(format+1, "+.%iE", acc);
if (acc > 9)
sprintf(format+6, " ");
else
sprintf(format+5, " ");
*format2 = '%';
sprintf(format2+1, "+.%iE", acc+3);
if (acc > 6)
sprintf(format2+6, " ");
else
sprintf(format2+5, " ");
i = 0;
currentname = defname;
/* From here on we freeze the input def */
if (startinfv -> arel[2]) {
if (!strcmp(startinfv -> arel[2] -> orifilename,currentname)) {
fprintf(stderr, "Warning: Input deffile will be overwritten by output deffile\n");
simparse_scn_arel_timestamp_late(startinfv -> arel[2]);
}
else if (!strcmp(startinfv -> arel[2] -> orifilename,deintername)) {
fprintf(stderr, "Warning: Input deffile will be overwritten by output smoothed deffile\n");
simparse_scn_arel_timestamp_late(startinfv -> arel[2]);
}
restimest = startinfv -> arel[2] -> timestamp;
}
while (i < 2) {
if (*currentname != '\0') {
/* Try to open the output, we overwrite */
if (!(stream = fopen(currentname, "w")))
goto error;
/* Now put the first line, copy from input */
tirout_a(startinfv -> arel, stream, "LOGNAME=");
/* Action should be taken over from prompt */
tirout_a(startinfv -> arel, stream, "ACTION=");
tirout_a(startinfv -> arel, stream, "PROMPT=");
tirout_a(startinfv -> arel, stream, "NCORES=");
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "INSET=");
/* tirout_a(startinfv -> arel, stream, "BOX="); */
tirout_a(startinfv -> arel, stream, "OUTSET=");
tirout_a(startinfv -> arel, stream, "OUTCUBUP=");
fprintf(stream, "\n");
/* tirout_a(startinfv -> arel, stream, "OKAY="); */
tirout_a(startinfv -> arel, stream, "PROGRESSLOG=");
tirout_a(startinfv -> arel, stream, "TEXTLOG=");
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "BMIN=");
tirout_a(startinfv -> arel, stream, "BMAJ=");
tirout_a(startinfv -> arel, stream, "BPA=");
tirout_a(startinfv -> arel, stream, "RMS=");
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "NDISKS=");
fprintf(stream, "NUR= %i", nrings);
fprintf(stream, "\n");
/* Now it depends on the file we are outputting */
if (currentname == defname) {
reparray = rpm -> par;
}
else {
lm1 =len-1;
/* Here, we have to filter */
for (j = 0; j < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS); ++j) {
/* Important: do not Hanning smooth the radii */
if (j != PRADI) {
{
for (k = 0; k < rpm -> nur; ++k) {
smsum = 0.0;
smweightsum = 0.0;
for (l = -len/2+1; l < len/2+1-1; ++l) {
/* if we exceed the ringnumbers, we take in the values at
the border */
/* if ((k+l) < 0) { */
/* valcur = rpm -> par[j*rpm -> nur]; */
/* } */
/* else if ((k+l) > rpm -> nur - 1) { */
/* valcur = rpm -> par[(j+1)*rpm -> nur-1]; */
/* } */
/* else { */
m = k+l;
if (m >= 0 && m < rpm -> nur) {
weight = 0.5*(1+cos(TWOPI*l/lm1));
smsum = smsum + weight * rpm -> par[j*rpm -> nur+m];
smweightsum = smweightsum + weight;
}
}
/* Use outarray as a buffer */
log -> outarray[j*rpm -> nur+k] = smsum/smweightsum;
/* Sort the array */
/* maths_bubble(smarray, len); */
/* if (!(j == PRADI) && ((n = ((j-NSSDPARAMS)%NDPARAMS + NSSDPARAMS)) == PXPOS || n == PYPOS)) */
/* fprintf(stream, format2, smarray[(len-1)/2]); */
/* else */
/* fprintf(stream, format, smarray[(len-1)/2]); */
}
}
}
}
reparray = log -> outarray;
}
/* put out the radii */
ftstab_putcoltitl(key, RADI);
fprintf(stream, "%8s= ", key);
for (m = 0; m < nrings; ++m) {
fprintf(stream, format, radii[m]);
}
fprintf(stream, "\n");
for (j = NSSDPARAMS; j < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS); ++j) {
/************/
/************/
k = 0;
while (k < rpm -> nur) {
if ((reparray[j*rpm -> nur+k]))
break;
++k;
}
if (k < rpm -> nur) {
/************/
/* Put the title */
ftstab_putcoltitl(key, j+1);
fprintf(stream, "%8s= ", key);
for (m = 0; m < nrings; ++m) {
/* Not sure if this is required, but do it anyway */
gsl_interp_accel_reset(rpm -> gsl_interp_accelarray[j-NSSDPARAMS]);
/* Very sure that this is a requirement; a test has shown */
/* gsl_interp_init(rpm -> gsl_interparray[j-NSSDPARAMS],rpm -> par+PRADI*rpm -> nur, rpm -> par + rpm -> nur*j, rpm -> nur); */
gsl_interp_init(rpm -> gsl_interparray[j-NSSDPARAMS],reparray+PRADI*rpm -> nur, reparray + rpm -> nur*j, rpm -> nur);
/* Search the first radius that is greater than the current, don't care about efficiency */
/* for (k = 1; k < rpm -> nur; ++k) { */
/* if (radii[m] < reparray[PRADI*rpm -> nur+k]) */
/* break; */
/* } */
/* Now we can interpolate or extrapolate */
/* Check for radius here */
if ( radii[m] < reparray[PRADI*rpm -> nur+rpm -> nur-1]) {
/* dpdr = (reparray[j*rpm -> nur+k]-reparray[j*rpm -> nur+k-1])/(reparray[PRADI*rpm -> nur+k]-reparray[PRADI*rpm -> nur+k-1]); */
/* dpdr = reparray[j*rpm -> nur+k-1]+dpdr*(radii[m]-reparray[PRADI*rpm -> nur+k-1]); */
dpdr = gsl_interp_eval(rpm -> gsl_interparray[j-NSSDPARAMS], rpm -> par+PRADI*rpm -> nur, rpm -> par + rpm -> nur*j, radii[m], rpm -> gsl_interp_accelarray[j-NSSDPARAMS]);
}
else {
dpdr = reparray[(j+1)*rpm -> nur-1];
}
if (!(j == PRADI) && ((n = ((j-NSSDPARAMS)%NDPARAMS + NSSDPARAMS)) == PXPOS || n == PYPOS)) {
fprintf(stream, format2, dpdr);
}
else {
fprintf(stream, format, dpdr);
}
}
fprintf(stream, "\n");
}
}
for (j = 0; j < NSPARAMS; ++j) {
ftstab_putcoltitl(key, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+j+1);
fprintf(stream, "%8s= ", key);
fprintf(stream, format, rpm -> par[(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur+j]);
}
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "LTYPE=");
for (disk = 1; disk < rpm -> ndisks; ++disk) {
sprintf(placer, "LTYPE_%i=" , disk+1);
tirout_a(startinfv -> arel, stream, placer);
}
/* Now put the rest of the input to the file */
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "CFLUX=");
for (disk = 1; disk < rpm -> ndisks; ++disk) {
sprintf(placer, "CFLUX_%i=" , disk+1);
tirout_a(startinfv -> arel, stream, placer);
}
tirout_a(startinfv -> arel, stream, "PENALTY=");
tirout_a(startinfv -> arel, stream, "WEIGHT=");
tirout_a(startinfv -> arel, stream, "RADSEP=");
/* tirout_a(startinfv -> arel, stream, "MEMMODE="); */
tirout_a(startinfv -> arel, stream, "INIMODE=");
tirout_a(startinfv -> arel, stream, "ISEED=");
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "FITMODE=");
tirout_a(startinfv -> arel, stream, "LOOPS=");
tirout_a(startinfv -> arel, stream, "MAXITER=");
tirout_a(startinfv -> arel, stream, "CALLITE=");
tirout_a(startinfv -> arel, stream, "SIZE=");
tirout_a(startinfv -> arel, stream, "INTY=");
tirout_a(startinfv -> arel, stream, "INDINTY=");
/* We want to hide the whole pswarm issue from the user, so we only spit it out if there have been changes to the defaults */
if (fit -> psse != PSW_PSSE_DEF) tirout_a(startinfv -> arel, stream, "PSSE=");
if (fit -> psnp != PSW_PSNP_DEF) tirout_a(startinfv -> arel, stream, "PSNP=");
if (fit -> psco != PSW_PSCO_DEF) tirout_a(startinfv -> arel, stream, "PSCO=");
if (fit -> psso != PSW_PSSO_DEF) tirout_a(startinfv -> arel, stream, "PSSO=");
if (fit -> psmv != PSW_PSMV_DEF) tirout_a(startinfv -> arel, stream, "PSMV=");
if (fit -> psnf != PSW_PSNF_DEF) tirout_a(startinfv -> arel, stream, "PSNF=");
if (fit -> psii != PSW_PSII_DEF) tirout_a(startinfv -> arel, stream, "PSII=");
if (fit -> psfi != PSW_PSFI_DEF) tirout_a(startinfv -> arel, stream, "PSFI=");
if (fit -> psid != PSW_PSID_DEF) tirout_a(startinfv -> arel, stream, "PSID=");
if (fit -> psdd != PSW_PSDD_DEF) tirout_a(startinfv -> arel, stream, "PSDD=");
fprintf(stream, "\n");
/* tirout_a(startinfv -> arel, stream, "ANSTART="); */
/* tirout_a(startinfv -> arel, stream, "ANEND="); */
/* tirout_a(startinfv -> arel, stream, "ANSTEPS="); */
/* tirout_a(startinfv -> arel, stream, "ISEED="); */
/* fprintf(stream, "\n"); */
fprintf(stream, "VARY= %s\n", fit -> varyhstr);
tirout_a(startinfv -> arel, stream, "VARINDX=");
/* tirout_a(startinfv -> arel, stream, "VARYMULT="); */
/* tirout_a(startinfv -> arel, stream, "VARYSING= "); */
tirout_a(startinfv -> arel, stream, "PARMAX=");
tirout_a(startinfv -> arel, stream, "PARMIN=");
tirout_a(startinfv -> arel, stream, "MODERATE=");
tirout_a(startinfv -> arel, stream, "DELSTART=");
tirout_a(startinfv -> arel, stream, "DELEND=");
tirout_a(startinfv -> arel, stream, "ITESTART=");
tirout_a(startinfv -> arel, stream, "ITEEND=");
tirout_a(startinfv -> arel, stream, "SATDELT=");
tirout_a(startinfv -> arel, stream, "MINDELTA=");
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "REGPARA=");
if ((fit -> reg_contv[0])) {
tirout_a(startinfv -> arel, stream, "REGDENO=");
tirout_a(startinfv -> arel, stream, "REGNUME=");
tirout_a(startinfv -> arel, stream, "REGTHRE=");
tirout_a(startinfv -> arel, stream, "REGWIDT=");
tirout_a(startinfv -> arel, stream, "REGAMPL=");
tirout_a(startinfv -> arel, stream, "REGASTE=");
tirout_a(startinfv -> arel, stream, "REGAMPD=");
}
fprintf(stream, "\n");
/* tirout_a(startinfv -> arel, stream, "TABLE="); */
/* tirout_a(startinfv -> arel, stream, "DISTANCE="); */
/* tirout_a(startinfv -> arel, stream, "REFRING="); */
/* tirout_a(startinfv -> arel, stream, "BIGTABLE="); */
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "TIRDEF=");
tirout_a(startinfv -> arel, stream, "TIRSMO=");
/* tirout_a(startinfv -> arel, stream, "TIRACC="); */
/* tirout_a(startinfv -> arel, stream, "TIRLEN="); */
fprintf(stream, "\n");
/* tirout_a(startinfv -> arel, stream, "HISNAME="); */
/* tirout_a(startinfv -> arel, stream, "HISTARTROW="); */
/* tirout_a(startinfv -> arel, stream, "HISTENDROW="); */
/* tirout_a(startinfv -> arel, stream, "HISKEY1="); */
/* tirout_a(startinfv -> arel, stream, "HISRING1="); */
/* tirout_a(startinfv -> arel, stream, "HISMIN1="); */
/* tirout_a(startinfv -> arel, stream, "HISMAX1="); */
/* tirout_a(startinfv -> arel, stream, "HISBINS1="); */
/* tirout_a(startinfv -> arel, stream, "HISDELTA1="); */
/* tirout_a(startinfv -> arel, stream, "HISKEY2="); */
/* tirout_a(startinfv -> arel, stream, "HISRING2="); */
/* tirout_a(startinfv -> arel, stream, "HISMIN2="); */
/* tirout_a(startinfv -> arel, stream, "HISMAX2="); */
/* tirout_a(startinfv -> arel, stream, "HISBINS2="); */
/* tirout_a(startinfv -> arel, stream, "HISDELTA2="); */
/* fprintf(stream, "\n"); */
tirout_a(startinfv -> arel, stream, "COOLGAL=");
tirout_a(startinfv -> arel, stream, "COOLBEAM=");
fprintf(stream, "\n");
/* tirout_a(startinfv -> arel, stream, "RECT="); */
/* tirout_a(startinfv -> arel, stream, "BIGRECT="); */
/* fprintf(stream, "\n"); */
tirout_a(startinfv -> arel, stream, "TILT=");
tirout_a(startinfv -> arel, stream, "BIGTILT=");
fprintf(stream, "\n");
/* tirout_a(startinfv -> arel, stream, "INCLINO="); */
/* tirout_a(startinfv -> arel, stream, "IN_REFINE="); */
fprintf(stream, "\n");
tirout_a(startinfv -> arel, stream, "GR_DEVICE=");
tirout_a(startinfv -> arel, stream, "GR_PARMS=");
tirout_a(startinfv -> arel, stream, "GR_XMIN=");
tirout_a(startinfv -> arel, stream, "GR_XMAX=");
tirout_a(startinfv -> arel, stream, "GR_MR=");
tirout_a(startinfv -> arel, stream, "GR_ML=");
tirout_a(startinfv -> arel, stream, "GR_TXHT=");
tirout_a(startinfv -> arel, stream, "GR_SBHT=");
tirout_a(startinfv -> arel, stream, "GR_LGND=");
tirout_a(startinfv -> arel, stream, "GR_SBRP=");
for (j = 1; j <= nrplts; ++j) {
fprintf(stream, "\n");
sprintf(inqstr, "GR_COL_%i=", j);
tirout_a(startinfv -> arel, stream, inqstr);
sprintf(inqstr, "GR_LINES_%i=", j);
tirout_a(startinfv -> arel, stream, inqstr);
sprintf(inqstr, "GR_INTERP_%i=", j);
tirout_a(startinfv -> arel, stream, inqstr);
sprintf(inqstr, "GR_ERRB_%i=", j);
tirout_a(startinfv -> arel, stream, inqstr);
sprintf(inqstr, "GR_YMIN_%i=", j);
tirout_a(startinfv -> arel, stream, inqstr);
sprintf(inqstr, "GR_YMAX_%i=", j);
tirout_a(startinfv -> arel, stream, inqstr);
/* sprintf(inqstr, "GR_NPAD_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
/* sprintf(inqstr, "GR_XPAD_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
/* sprintf(inqstr, "GR_YPAD_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
/* sprintf(inqstr, "GR_ERAD_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
/* sprintf(inqstr, "GR_EBAD_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
/* sprintf(inqstr, "GR_COAD_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
/* sprintf(inqstr, "GR_LIAD_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
/* sprintf(inqstr, "GR_INTERPAD_%i_%i=", j); */
/* tirout_a(startinfv -> arel, stream, inqstr); */
}
fclose(stream);
}
currentname = deintername;
++i;
}
if (startinfv -> arel[2]) {
startinfv -> arel[2] -> timestamp = restimest;
}
/* Reset outarray to the original state */
for (i = 0; i < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++i){
log -> outarray[i] = rpm -> par[i];
}
free(radii);
if ((defname))
free(defname);
if ((deintername))
free(deintername);
if ((varystr))
freeparsed(varystr);
return 1;
error:
if ((radii))
free(radii);
if ((defname))
free(defname);
if ((deintername))
free(deintername);
if ((varystr))
freeparsed(varystr);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Copies a part of the gipsy input to a stream */
static int tirout_a(simparse_scn_arel **arel, FILE *stream, char *keyword)
{
/* int def = 2; */
/* int length; */
/* char mes[2]; */
/* int i; */
char *varyhstr = NULL;
int keypres, nread, nreturned;
if (simparse_scn_arel_readval_stringwhitesp(arel, keyword, "", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &varyhstr)) {
if ((varyhstr))
free(varyhstr);
return 1;
}
fprintf(stream, "%s%s\n", keyword, varyhstr);
free(varyhstr);
return 0;
/* sprintf(mes, "A"); */
/* Initialise */
/* { */
/* for (i = 0; i < VARYHSTRELES-2; ++i) { */
/* input[i] = ' '; */
/* } */
/* input[i] = '\0'; */
/* Get the value */
/* length = usertext_tir(input, &def, keyword,mes); */
/* input[length] = '\0'; */
/* Copy it into the file */
/* fprintf(stream, "%s %s\n", keyword); */
/* } */
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Get a double parameter */
static int get_parameter_double(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, char *mess, char *parname, int ident, int force)
{
int def; /* Any default mode */
int nel; /* Number of elements */
int i; /* Simple control variables */
int nident;
/**************/
/**************/
/* int obsint = 0; */
/* char obsmes[80]; */
/**************/
/* Make this transformation to identify higher-order VSYS XPOS and YPOS */
nident = (ident-NSSDPARAMS)%NDPARAMS + NSSDPARAMS;
/* Read values that are needed only in this module */
/* First from the log if present */
/* Default is 0 */
for (i = 0; i < rpm -> nur; ++i)
*(rpm -> par + rpm -> nur*ident+i) = 0.0;
def = force;
nel = 0;
/* This is the third parameter sequence */
if (!(startinfv -> firstrun))
cancel_tir(startinfv -> arel, parname, 0);
nel = userdble_tir(startinfv -> arel, rpm -> par+ident*rpm -> nur, &rpm -> nur, &def, parname, mess);
if (!nel)
nel = rpm -> nur;
/* Check for errors and extrapolate */
for (i = 0; i < rpm -> nur; ++i) {
if (i > nel-1) {
rpm -> par[ident*rpm -> nur+i] = rpm -> par[ident*rpm -> nur+nel-1];
}
else {
if ((ident == PRADI) || !(nident == PXPOS || nident == PVSYS || nident == PYPOS)) {
rpm -> par[ident*rpm ->nur+i] = dparamtointern(rpm -> par[ident*rpm ->nur+i], ident+1, hdr, rpm -> ndisks);
}
}
}
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Produces the tiltogram output of tirific */
static int tiltout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
int i,j;
/* int def = 2; */
/* int nel = 1; */
/* char mes[81]; */
char *filename = NULL;
qfits_header *header = NULL;
float *array = NULL;
double nrefr[3];
double nr[3];
char value[21];
char **varystr = NULL;
int keypres, nread, nreturned;
/* Initialise the input array */
/* for (i = 0; i < 200; ++i) { */
/* filename[i] = ' '; */
/* } */
/* filename[200] = '\0'; */
/* sprintf(mes, "Give a filename for a tiltogram output"); */
/* userchar_tir(filename, &nel, &def, "TILT=", mes); */
/* termsinglestr(filename); */
/* cancel_tir(startinfv -> arel, "TILT"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "TILT", "Give a filename for a tiltogram output.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(filename = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(filename = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
if (*filename != '\0') {
if (rpm -> nur < 2)
return 1;
/* Read in the values */
tir_get_grid(log, rpm, log -> outarray);
/* Make a header */
/* The bitpix is -32 */
if (!(header = ftsout_putcard(header, "BITPIX","-32")))
goto error;
/* The number of axes is set to three */
if (!ftsout_putcard(header, "NAXIS","2"))
goto error;
/* Now get the axis numbers */
sprintf(value, "%i", rpm -> nur);
if (!ftsout_putcard(header, "NAXIS1",value))
goto error;
sprintf(value, "%i", rpm -> nur);
if (!ftsout_putcard(header, "NAXIS2",value))
goto error;
/* May contain an extension */
if (!ftsout_putcard(header, "EXTEND","T"))
goto error;
/* These are clear */
if (!ftsout_putcard(header, "BSCALE","1"))
goto error;
if (!ftsout_putcard(header, "BZERO","0"))
goto error;
/* The bunit is Jy*km/s/beam, while this is the 3d beam */
if (!ftsout_putcard(header, "BUNIT","'deg '"))
goto error;
/* The cdelt is the difference between the first two rings */
sprintf(value, "%.12E", log -> outarray[PRADI*rpm -> nur+1]-log -> outarray[PRADI*rpm -> nur]);
if (!ftsout_putcard(header, "CDELT1", value))
goto error;
/* The crpix is 1 */
sprintf(value, "%.12E", 1.0);
if (!ftsout_putcard(header, "CRPIX1", value))
goto error;
/* The crval in user units -> arcsec is 0 */
sprintf(value, "%.12E", 0.0);
if (!ftsout_putcard(header, "CRVAL1", value))
goto error;
/* ctype is angle ... */
if (!ftsout_putcard(header, "CTYPE1", "'ANGLE '"))
goto error;
if (!ftsout_putcard(header, "CUNIT1", "'arcsec '"))
goto error;
/* The cdelt is the difference between the first two rings */
sprintf(value, "%.12E", log -> outarray[PRADI*rpm -> nur+1]-log -> outarray[PRADI*rpm -> nur]);
if (!ftsout_putcard(header, "CDELT2", value))
goto error;
/* The crpix is 1 */
sprintf(value, "%.12E", 1.0);
if (!ftsout_putcard(header, "CRPIX2", value))
goto error;
/* The crval in user units -> arcsec is 0 */
sprintf(value, "%.12E", 0.0);
if (!ftsout_putcard(header, "CRVAL2", value))
goto error;
/* ctype is angle ... */
if (!ftsout_putcard(header, "CTYPE2", "'ANGLE '"))
goto error;
if (!ftsout_putcard(header, "CUNIT2", "'arcsec '"))
goto error;
/* After that allocate the memory */
if (!(array = (float *) malloc(rpm -> nur*rpm -> nur*sizeof(float))))
goto error;
/* Convert to internal units (radian) */
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur + NSPARAMS; ++i) {
rpm -> par[i] = log -> outarray[i];
}
changetointern(rpm -> par, rpm -> nur, hdr, rpm -> ndisks);
/* Now fill the array */
for (i = 0; i < rpm -> nur; ++i) {
/* Now get the normal vector of the reference ring */
nrefr[0] = sin(rpm -> par[PINCL*rpm -> nur+i])*sinf(rpm -> par[PPA*rpm -> nur+i]);
nrefr[1] = -sin(rpm -> par[PINCL*rpm -> nur+i])*cosf(rpm -> par[PPA*rpm -> nur+i]);
nrefr[2] = cos(rpm -> par[PINCL*rpm -> nur+i]);
/* Now we read in the values */
for (j = 0; j < rpm -> nur; ++j) {
nr[0] = sin(rpm -> par[PINCL*rpm -> nur+j])*sinf(rpm -> par[PPA*rpm -> nur+j]);
nr[1] = -sin(rpm -> par[PINCL*rpm -> nur+j])*cosf(rpm -> par[PPA*rpm -> nur+j]);
nr[2] = cos(rpm -> par[PINCL*rpm -> nur+j]);
/* This is the arcus */
array[i+rpm -> nur*j] = (nr[0]*nrefr[0]+nr[1]*nrefr[1]+nr[2]*nrefr[2]) > 1?0.0:RADTODEG*acos(nr[0]*nrefr[0]+nr[1]*nrefr[1]+nr[2]*nrefr[2]);
}
}
/* Put it to the disk */
ftsout_writeimage(filename, array, header, rpm -> nur, rpm -> nur);
/* Clear things */
ftsout_header_destroy(header);
free(array);
}
/* Initialise the input array */
/* for (i = 0; i < 19; ++i) { */
/* filename[i] = ' '; */
/* } */
/* filename[i] = '\0'; */
/* sprintf(mes, "Give a filename for a big tiltogram output"); */
/* userchar_tir(filename, &nel, &def, "BIGTILT=", mes); */
/* termsinglestr(filename); */
if ((filename)){
free(filename);
filename = NULL;
}
/* cancel_tir(startinfv -> arel, "BIGTILT"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "BIGTILT", "Give a filename for a big tiltogram output", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(filename = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(filename = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
if (*filename != '\0') {
if (rpm -> nr < 2)
return 1;
/* Make a header */
/* The bitpix is -32 */
header = NULL;
if (!(header = ftsout_putcard(header, "BITPIX","-32")))
goto error;
/* The number of axes is set to three */
if (!ftsout_putcard(header, "NAXIS","2"))
goto error;
/* Now get the axis numbers */
sprintf(value, "%i", rpm -> nr);
if (!ftsout_putcard(header, "NAXIS1",value))
goto error;
sprintf(value, "%i", rpm -> nr);
if (!ftsout_putcard(header, "NAXIS2",value))
goto error;
/* May contain an extension */
if (!ftsout_putcard(header, "EXTEND","T"))
goto error;
/* These are clear */
if (!ftsout_putcard(header, "BSCALE","1"))
goto error;
if (!ftsout_putcard(header, "BZERO","0"))
goto error;
/* The bunit is Jy*km/s/beam, while this is the 3d beam */
if (!ftsout_putcard(header, "BUNIT","'deg '"))
goto error;
/* The cdelt is the width of one ring */
sprintf(value, "%.12E", dinterntoparam(rpm -> radsep, RADI, hdr, rpm -> ndisks));
if (!ftsout_putcard(header, "CDELT1", value))
goto error;
/* The crpix is 1 */
sprintf(value, "%.12E", 1.0);
if (!ftsout_putcard(header, "CRPIX1", value))
goto error;
/* The crval in user units -> arcsec is 1/2 radsep */
sprintf(value, "%.12E", dinterntoparam(rpm -> radsep, RADI, hdr, rpm -> ndisks)/2);
if (!ftsout_putcard(header, "CRVAL1", value))
goto error;
/* ctype is angle ... */
if (!ftsout_putcard(header, "CTYPE1", "'ANGLE '"))
goto error;
if (!ftsout_putcard(header, "CUNIT1", "'arcsec '"))
goto error;
/* The cdelt is the width of one ring */
sprintf(value, "%.12E", dinterntoparam(rpm -> radsep, RADI, hdr, rpm -> ndisks));
if (!ftsout_putcard(header, "CDELT2", value))
goto error;
/* The crpix is 1 */
sprintf(value, "%.12E", 1.0);
if (!ftsout_putcard(header, "CRPIX2", value))
goto error;
/* The crval in user units -> arcsec is 1/2 radsep */
sprintf(value, "%.12E", dinterntoparam(rpm -> radsep, RADI, hdr, rpm -> ndisks)/2);
if (!ftsout_putcard(header, "CRVAL2", value))
goto error;
/* ctype is angle ... */
if (!ftsout_putcard(header, "CTYPE2", "'ANGLE '"))
goto error;
if (!ftsout_putcard(header, "CUNIT2", "'arcsec '"))
goto error;
/* After that allocate the memory */
if (!(array = (float *) malloc(rpm -> nr*rpm -> nr*sizeof(float))))
goto error;
/* Read in the values */
tir_get_grid(log, rpm, log -> outarray);
/* Convert to internal units (radian) */
for (i = 0; i < (NPARAMS+(rpm -> ndisks-1)*NDPARAMS)*rpm -> nur + NSPARAMS; ++i) {
rpm -> par[i] = log -> outarray[i];
}
changetointern(rpm -> par, rpm -> nur, hdr, rpm -> ndisks);
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
interpover(rpm, rpm -> radsep, 0, NULL, fit -> index);
/* Now fill the array */
for (i = 0; i < rpm -> nr; ++i) {
/* Now get the normal vector of the reference ring */
nrefr[0] = sin(rpm -> modpar[PINCL*rpm -> nr+i])*sinf(rpm -> modpar[PPA*rpm -> nr+i]);
nrefr[1] = -sin(rpm -> modpar[PINCL*rpm -> nr+i])*cosf(rpm -> modpar[PPA*rpm -> nr+i]);
nrefr[2] = cos(rpm -> modpar[PINCL*rpm -> nr+i]);
/* Now we read in the values */
for (j = 0; j < rpm -> nr; ++j) {
nr[0] = sin(rpm -> modpar[PINCL*rpm -> nr+j])*sinf(rpm -> modpar[PPA*rpm -> nr+j]);
nr[1] = -sin(rpm -> modpar[PINCL*rpm -> nr+j])*cosf(rpm -> modpar[PPA*rpm -> nr+j]);
nr[2] = cos(rpm -> modpar[PINCL*rpm -> nr+j]);
/* This is the arcus */
array[i+rpm -> nr*j] = (nr[0]*nrefr[0]+nr[1]*nrefr[1]+nr[2]*nrefr[2]) > 1?0.0:RADTODEG*acos(nr[0]*nrefr[0]+nr[1]*nrefr[1]+nr[2]*nrefr[2]);
}
}
/* Put it to the disk */
ftsout_writeimage(filename, array, header, rpm -> nr, rpm -> nr);
/* Clear things */
ftsout_header_destroy(header);
free(array);
}
free(filename);
return 1;
error:
if ((header))
ftsout_header_destroy(header);
if ((array))
free(array);
if ((filename))
free(filename);
if ((varystr))
freeparsed(varystr);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Produces the tip-lon output of tirific */
static int briggsout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
char mes[81];
int i, j, ok, nel, def, dev;
char *br_device = NULL;
double br_pa;
float pa_float;
double br_incl;
double pa;
double inc;
int br_annr;
float rmax;
float *br_angl = NULL;
int br_swdth;
int br_cwdth;
int br_lwdth;
int br_col = 1;
int br_refl;
int numplpts;
float *xarray = NULL;
float *xlarray = NULL;
float *yarray = NULL;
float *dummyarray = NULL;
float *ylarray = NULL;
double nrefr[3];
double rota[3];
int nread, nreturned, keypres;
char **varystr = NULL;
/**************/
/**************/
/* int obsint = 0; */
/* char obsmes[80]; */
/**************/
/**************/
/**************/
/* sprintf(obsmes, "graph: x: %.2f y: %.2f", x,y); */
/* anyout_tir(&obsint, obsmes); */
/**************/
/* Keywords:
BR_DEVICE= pgplot device
BR_PA= position angle of reference ring
BR_INCL= inclination of reference ring
BR_ANNR= circles to plot
BR_ANGL= circle radii in deg
BR_SWDTH= dot width
BR_CWDTH= circle width
BR_LWDTH= line width
BR_REFL= Plot reference line?
BR_COL= Colour of dots and lines
*/
/* Ask the user for the output device */
/* for (j = 0; j < 200; ++j) { */
/* br_device[j] = ' '; */
/* } */
/* br_device[200] = '\0'; */
/* sprintf(mes, "Give graphics (pgplot) device:"); */
/* def = 2; */
/* nel = 1; */
/* userchar_tir(br_device, &nel, &def, "BR_DEVICE=", mes); */
/* termsinglestr(br_device); */
/* cancel_tir(startinfv -> arel, "BR_DEVICE"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "BR_DEVICE", "Give a progress file name for no point actually when you can read this.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(br_device = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(br_device = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* If there was no input we return */
if (*br_device == '\0') {
free(br_device);
return 0;
}
/* Check if there was a logfile and stop if there wasn't */
/* if (*log -> logname == '\0') */
/* return 0; */
/* Ask for the reference position angle, default 0 */
sprintf(mes, "Give Briggs reference position angle");
br_pa = 0;
def = 2;
nel = 1;
userdble_tir(startinfv -> arel, &br_pa, &nel, &def, "BR_PA=", mes);
/* Ask for the reference inclination, default 0 */
sprintf(mes, "Give Briggs reference position angle");
br_incl = 0;
def = 2;
nel = 1;
userdble_tir(startinfv -> arel, &br_incl, &nel, &def, "BR_INCL=", mes);
/* Then get the stuff in radian */
inc = DEGTORAD*br_incl;
pa = DEGTORAD*br_pa;
/* Ask for the angles to plot rings for */
ok = 0;
def = 2;
while (ok == 0) {
sprintf(mes, "Give number of Briggs angles");
br_annr = 0;
nel = 1;
userint_tir(startinfv -> arel, &br_annr, &nel, &def, "BR_ANNR=", mes);
if (br_annr < 0) {
dev = 0;
sprintf(mes, "Must be a positive number");
anyout_tir(&dev,mes);
cancel_tir(startinfv -> arel, "BR_ANNR=", 2);
def = 0;
}
else
ok = 1;
}
/* Symbol width */
ok = 0;
def = 2;
while (ok == 0) {
sprintf(mes, "Give width of dots (1-201) [5]");
br_swdth = 10;
nel = 1;
userint_tir(startinfv -> arel, &br_swdth, &nel, &def, "BR_SWDTH=", mes);
if ((br_swdth < 1) || (br_swdth > 201)) {
dev = 0;
sprintf(mes, "Must be in-between 1 and 201");
anyout_tir(&dev,mes);
cancel_tir(startinfv -> arel, "BR_SWDTH=", 2);
def = 1;
}
else
ok = 1;
}
/* circle width */
ok = 0;
def = 2;
while (ok == 0) {
sprintf(mes, "Give width of circles (1-201) [1]");
br_cwdth = 2;
nel = 1;
userint_tir(startinfv -> arel, &br_cwdth, &nel, &def, "BR_CWDTH=", mes);
if ((br_cwdth < 1) || (br_cwdth > 201)) {
dev = 0;
sprintf(mes, "Must be in-between 1 and 201");
anyout_tir(&dev,mes);
cancel_tir(startinfv -> arel, "BR_CWDTH=", 2);
def = 1;
}
else
ok = 1;
}
/* line width */
ok = 0;
def = 2;
while (ok == 0) {
sprintf(mes, "Give width of lines (1-201) [1]");
br_lwdth = 2;
nel = 1;
userint_tir(startinfv -> arel, &br_lwdth, &nel, &def, "BR_LWDTH=", mes);
if ((br_lwdth < 1) || (br_lwdth > 201)) {
dev = 0;
sprintf(mes, "Must be in-between 1 and 201");
anyout_tir(&dev,mes);
cancel_tir(startinfv -> arel, "BR_LWDTH=", 2);
def = 1;
}
else
ok = 1;
}
/* Ask whether to plot the reference line */
sprintf(mes, "Plot reference line? [1]");
def = 2;
br_refl = 1;
nel = 1;
userint_tir(startinfv -> arel, &br_refl, &nel, &def, "BR_REFL=", mes);
/* Ask for colour */
sprintf(mes, "Colour of dots and lines");
br_col = 1;
def = 2;
nel = 1;
userint_tir(startinfv -> arel, &br_col, &nel, &def, "BR_COL=", mes);
/* Allocate memory */
if (!(xarray = (float *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(yarray = (float *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(dummyarray = (float *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(xlarray = (float *) malloc((rpm -> nr*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(ylarray = (float *) malloc((rpm -> nr*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
/* We read all values into the outarray */
tir_get_grid(log, rpm, log -> outarray);
/* And then into the par array */
for (j = 0; j < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++j)
rpm -> par[j] = log -> outarray[j];
/* Interpolate over */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
interpover(rpm, dinterntoparam(rpm -> radsep, RADI, hdr, rpm -> ndisks), 0, NULL, fit -> index);
/* Now fill the arrays */
for (j = 0; j < rpm -> nur; ++j) {
/* Normal vector of current ring */
nrefr[0] = sin(DEGTORAD*rpm -> par[PINCL*rpm -> nur+j])*sin(DEGTORAD*rpm -> par[PPA*rpm -> nur+j]);
nrefr[1] = -sin(DEGTORAD*rpm -> par[PINCL*rpm -> nur+j])*cos(DEGTORAD*rpm -> par[PPA*rpm -> nur+j]);
nrefr[2] = cos(DEGTORAD*rpm -> par[PINCL*rpm -> nur+j]);
/* Rotate the ring clockwise about the LOS */
rota[0] = cos(pa)*nrefr[0]+sin(pa)*nrefr[1];
rota[1] = -sin(pa)*nrefr[0]+cos(pa)*nrefr[1];
rota[2] = nrefr[2];
/* Then rotate the ring about the x axis, clockwise */
rota[1] = cos(inc)*rota[1]+sin(inc)*rota[2];
/* Finally get back to the original position with a clockwise rotation about the LOS */
xarray[j] = rota[0];
yarray[j] = rota[1];
/**************/
/* sprintf(obsmes, "graph: x: %.2f y: %.2f", xarray[j],yarray[j]); */
/* anyout_tir(&obsint, obsmes); */
/**************/
/* xarray[j] = cos(pa)*rota[0]-sin(pa)*rota[1]; */
/* yarray[j] = sin(pa)*rota[0]+cos(pa)*rota[1]; */
}
/* Do the same with the large array */
for (j = 0; j < rpm -> nr; ++j) {
/* Normal vector of current ring */
nrefr[0] = sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*sin(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nrefr[1] = -sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*cos(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nrefr[2] = cos(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j]);
/* Rotate the ring clockwise about the LOS */
rota[0] = cos(pa)*nrefr[0]+sin(pa)*nrefr[1];
rota[1] = -sin(pa)*nrefr[0]+cos(pa)*nrefr[1];
rota[2] = nrefr[2];
/* Then rotate the ring about the x axis, clockwise */
rota[1] = cos(inc)*rota[1]+sin(inc)*rota[2];
/* Finally get back to the original position with a clockwise rotation about the LOS */
xlarray[j] = cos(pa)*rota[0]-sin(pa)*rota[1];
ylarray[j] = sin(pa)*rota[0]+cos(pa)*rota[1];
xlarray[j] = rota[0];
ylarray[j] = rota[1];
}
/* In order to provide the user with some suggestion */
rmax = 0;
for (j = 0; j < rpm -> nur; ++j) {
if (rmax < sqrt(xarray[j]*xarray[j]+yarray[j]*yarray[j]))
rmax = sqrt(xarray[j]*xarray[j]+yarray[j]*yarray[j]);
}
for (j = 0; j < rpm -> nr; ++j) {
if (rmax < sqrt(xlarray[j]*xlarray[j]+ylarray[j]*ylarray[j]))
rmax = sqrt(xlarray[j]*xlarray[j]+ylarray[j]*ylarray[j]);
}
if (rmax > 1.0)
rmax = 1.0;
rmax = asin(rmax)/DEGTORAD;
if ((br_annr)) {
if (!(br_angl = (float *) malloc(br_annr*sizeof(float))))
goto error;
/* Now get the numbers */
sprintf(mes, "Give %i Briggs angles, calculated max: %.1f",br_annr,rmax);
def = 5;
nel = br_annr;
userreal_tir(startinfv -> arel, br_angl, &nel, &def, "BR_ANGL=", mes);
}
/* Calculate the proper radii for the rings */
for (j = 0; j < br_annr; ++j)
br_angl[j] = sin(DEGTORAD*br_angl[j]);
/* Now pass it to the graphics */
pgp_opendev(br_device);
pa_float = br_pa;
/* remove indexed data points */
numplpts = gr_deleteindexed(rpm -> nur, (NPARAMS+(rpm -> ndisks-1)*NDPARAMS+1), xarray, yarray, dummyarray, fit -> index, rpm -> ndisks);
/* numplpts = rpm -> nur; */
/* then plot */
if (!numplpts)
numplpts = 1;
pgp_polar(numplpts, xarray, yarray, rpm -> nr, xlarray, ylarray, br_annr, br_angl, (br_refl)?(&pa_float):NULL, br_lwdth, br_cwdth, br_swdth, br_col);
/* Once we got here, we ask the user if to continue */
sprintf(mes, "Continue (Press return)?");
def = 1;
nel = 1;
userint_tir(startinfv -> arel, &br_swdth, &nel, &def, "BR_CONT=", mes);
/* Then we stop it */
pgp_end();
free(xarray);
free(xlarray);
free(yarray);
free(dummyarray);
free(ylarray);
if ((br_angl))
free(br_angl);
if ((br_device))
free(br_device);
return 0;
error:
if ((br_angl))
free(br_angl);
if ((xarray))
free(xarray);
if ((xlarray))
free(xlarray);
if ((yarray))
free(yarray);
if ((dummyarray))
free(dummyarray);
if ((ylarray))
free(ylarray);
if ((br_device))
free(br_device);
if ((varystr))
freeparsed(varystr);
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Produces the graphics output of tirific */
static int graphout(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
pgp_gdsc *gdsc = NULL;
float *xarray = NULL;
float *xarray2 = NULL;
float *yarray = NULL;
float *yerrarray = NULL;
float *xlarray = NULL;
float *ylarray = NULL;
float xmin;
float xmax;
float ymin;
float ymax;
int bars;
float barwidth;
int posrefr;
double xrefp;
double yrefp;
char **varystr = NULL;
char *varyhstr = NULL;
char *strbef = NULL;
int i, j, k, dev, def, nel, inword, nrplts, dummy;
char mes[200];
char *pgdevice = NULL;
char inqstr[24];
int colour;
int lines;
int interp;
int errbars;
int symb;
int fill;
float sizer;
char leftdeschi[8];
char rightdeschi[8];
char leftdesclo[30];
char rightdesclo[30];
char bottomdeschi[8];
char bottomdesclo[30];
char topdesclo[30];
char topdeschi[30];
float lrzero;
float lrscale;
float btzero;
float btscale;
int xlog;
int ylog;
int numplpts, ident;
char legend[80];
int pltlegend;
int nradd = 0;
int *npadd = NULL;
float **xval = NULL;
float **yval = NULL;
float **errb = NULL;
int *erad = NULL;
int *adcol = NULL;
int *adfill = NULL;
int *adsymb = NULL;
int *adlines = NULL;
int *adinterp = NULL;
float *adsizer = NULL;
int verln, horln;
float *vertarray = NULL, *horarray = NULL;
int *vertcarray = NULL, *horcarray = NULL;
float vhlxs[2],vhlys[2];
int keypres, nread, nreturned;
/* Ask the user for the output device */
/* for (i = 0; i < 200; ++i) { */
/* pgdevice[i] = ' '; */
/* } */
/* pgdevice[200] = '\0'; */
/* sprintf(mes, "Give graphics (pgplot) device:"); */
/* def = 2; */
/* nel = 1; */
/* userchar_tir(pgdevice, &nel, &def, "GR_DEVICE=", mes); */
/* termsinglestr(pgdevice); */
/* cancel_tir(startinfv -> arel, "GR_DEVICE"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "GR_DEVICE", "Give graphics (pgplot) device.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr)) {
goto error;
}
if ((varystr[0])) {
if (!(pgdevice = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(pgdevice = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
/* If there was no input we return */
if (*pgdevice == '\0') {
free(pgdevice);
return 0;
}
/* Check if there was a logfile and stop if there wasn't */
/* if (*log -> logname == '\0') */
/* return 0; */
/* Allocate the complicated varystr */
if (!(varystr = (char **) malloc(MAXGRAPHS*sizeof(char *))))
goto error;
/* if (!(varyhstr = getfcharray(VARYHSTRELES, NULL))) */
/* goto error; */
/* Then ask for the things to plot */
/* sprintf(mes, "Give parameters to plot"); */
/* def = 0; */
/* nel = usertext_tir(varyhstr, &def, "GR_PARMS=",mes); */
/* Terminate the string */
/* varyhstr[nel] = '\0'; */
if ((varyhstr))
free(varyhstr);
if (simparse_scn_arel_readval_string(startinfv -> arel, "GR_PARMS", "Give parameters to plot.", 0, "", 0, -1, 0, 0, &keypres, &nread, &nreturned, &varyhstr)) {
goto error;
}
/* Change the case if it is lower case */
i = 0;
while (varyhstr[i]) {
if (varyhstr[i] >= 'a' && varyhstr[i] <= 'z')
varyhstr[i] = varyhstr[i]+'A'-'a';
++i;
}
/* Now hack it into peaces, fill varystr, ignoring wrong parameters */
inword = 0;
i = 0;
nrplts = 0;
while (varyhstr[i] != '\0') {
if ((inword)) {
if (varyhstr[i] == ' ' || varyhstr[i] == '\t') {
varyhstr[i] = '\0';
if ((ident = get_graphident(strbef, NULL, NULL, NULL, NULL, rpm -> ndisks)) > 0) {
varystr[nrplts] = strbef;
++nrplts;
}
inword = 0;
}
else if (varyhstr[i+1] == '\0') {
if ((ident = get_graphident(strbef, NULL, NULL, NULL, NULL, rpm -> ndisks)) > 0) {
varystr[nrplts] = strbef;
++nrplts;
}
}
}
else if (varyhstr[i] != ' ' && varyhstr[i] != '\t') {
if (nrplts < MAXGRAPHS)
strbef = varyhstr+i;
inword = 1;
}
++i;
}
dev = 1;
if (nrplts < 2) {
sprintf(mes, "Something wrong with GR_PARMS=, no output");
anyout_tir(&dev, mes);
}
/* Allocate memory for the output */
if (!(xarray = (float *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(xarray2 = (float *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(yarray = (float *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(yerrarray = (float *) malloc((rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(xlarray = (float *) malloc((rpm -> nr*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
if (!(ylarray = (float *) malloc((rpm -> nr*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS)*sizeof(float))))
goto error;
/* We read all values into the outarray */
tir_get_grid(log, rpm, log -> outarray);
/* Then into the par array */
for (j = 0; j < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++j)
rpm -> par[j] = log -> outarray[j];
/* Get the reference positions */
/* First ask for the reference ring */
sprintf(mes, "Position reference ring [1]");
def = 2;
nel = 1;
posrefr = 1;
userint_tir(startinfv -> arel, &posrefr, &nel, &def, "GR_PRFR=", mes);
if ((posrefr < 1) || (posrefr > rpm -> nur))
posrefr = 1;
else
--posrefr;
/* Then this will be a default for the reference position */
sprintf(mes, "Reference Right Ascension [%.3f]",rpm -> par[PXPOS*rpm -> nur+posrefr]);
def = 2;
nel = 1;
xrefp = rpm -> par[PXPOS*rpm -> nur+posrefr];
userdble_tir(startinfv -> arel, &xrefp, &nel, &def, "GR_PRFX=", mes);
/* Export this to log */
log -> xref = xrefp;
sprintf(mes, "Reference Declination [%.3f]",rpm -> par[PYPOS*rpm -> nur+posrefr]);
def = 2;
nel = 1;
yrefp = rpm -> par[PYPOS*rpm -> nur+posrefr];
userdble_tir(startinfv -> arel, &yrefp, &nel, &def, "GR_PRFY=", mes);
/* Export this to log */
log -> yref = yrefp;
/* Interpolate over */
for (i = rpm -> nur*NSSDPARAMS; i < rpm->nur *(NSSDPARAMS+NDPARAMS*rpm->ndisks); ++i)
rpm -> chapar[i] = 1;
if (changedependent(rpm, rpm -> par, fit -> index, rpm -> chapar) < 0)
goto error;
interpover(rpm, barwidth = dinterntoparam(rpm -> radsep, RADI, hdr, rpm -> ndisks), 0, NULL, fit -> index);
/* Now prepare the arrays for x */
fillgrapharray(startinfv, hdr, rpm, ident = get_graphident(varystr[0], NULL, NULL, NULL, NULL, rpm -> ndisks), xarray, xlarray, rpm -> ndisks);
/* Get the scale and the identity card */
gr_fillscaling(log, hdr, get_graphident(varystr[0], bottomdeschi, bottomdesclo, topdesclo, legend, rpm -> ndisks), &btscale, &btzero, rpm -> ndisks);
/* Inquire whether to plot subrings */
sprintf(mes, "Plot values for subrings 1/0? [1]");
def = 2;
nel = 1;
bars = 1;
userint_tir(startinfv -> arel, &bars, &nel, &def, "GR_SBRP=", mes);
/* Get min */
xmin = xarray[0];
for (i = 1; i < rpm -> nur; ++i)
xmin = (xmin > xarray[i])?xarray[i]:xmin;
if ((bars))
for (i = 0; i < rpm -> nr; ++i)
xmin = (xmin > xlarray[i])?xlarray[i]:xmin;
/* Get max */
xmax = xarray[0];
for (i = 1; i < rpm -> nur; ++i)
xmax = (xmax < xarray[i])?xarray[i]:xmax;
if ((bars))
for (i = 0; i < rpm -> nr; ++i)
xmax = (xmax < xlarray[i])?xlarray[i]:xmax;
/* Inquire min and max */
sprintf(mes, "Give minimum of x-axis [%f]", xmin);
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &xmin, &nel, &def, "GR_XMIN=", mes);
sprintf(mes, "Give maximum of x-axis [%f]", xmax);
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &xmax, &nel, &def, "GR_XMAX=", mes);
/* Inquire x-axis style */
sprintf(mes, "Logarithmic scaling of x-axis? (1/0)");
xlog = 0;
def = 2;
nel = 1;
userint_tir(startinfv -> arel, &xlog, &nel, &def, "GR_XLOG=", mes);
if ((xlog))
xlog = 1;
/* In case of SBR, the right hand is SD */
if (ident == SBR)
gr_fillaxis((NPARAMS+(rpm -> ndisks-1)*NDPARAMS+DENS_GRAPHNR), topdeschi, rpm -> ndisks);
else if (ident == XPOS) {
gr_fillaxis((NPARAMS+(rpm -> ndisks-1)*NDPARAMS+RASH_GRAPHNR), topdeschi, rpm -> ndisks);
xlog = 2;
}
else if (ident == YPOS) {
gr_fillaxis((NPARAMS+(rpm -> ndisks-1)*NDPARAMS+DESH_GRAPHNR), topdeschi, rpm -> ndisks);
xlog = 3;
}
else {
gr_fillaxis(ident, topdeschi, rpm -> ndisks);
}
/* Ask whether to plot a legend */
sprintf(mes, "Plot legend (1/0)?");
def = 2;
nel = 1;
pltlegend = 1;
userint_tir(startinfv -> arel, &pltlegend, &nel, &def, "GR_LGND=", mes);
/* Now initialise the graphics */
pgp_opendev(pgdevice);
/* Generate the standard frame information */
gdsc = pgp_gdsc_default(nrplts-1, 2, (pltlegend)?((nrplts+1)/2):0, 1.0);
/* Make the adjustment of left and right frame possible */
sprintf(mes, "Give right hand margin");
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &gdsc -> rightmargin, &nel, &def, "GR_MR=", mes);
sprintf(mes, "Give left hand margin");
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &gdsc -> leftmargin, &nel, &def, "GR_ML=", mes);
/* Ask for the height of text and symbols */
sprintf(mes, "Give height of Text");
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &gdsc -> numberheight, &nel, &def, "GR_TXHT=", mes);
sprintf(mes, "Give height of symbols");
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &gdsc -> symbolheight, &nel, &def, "GR_SBHT=", mes);
/* Legendheight and axdescheight are 1 by default, we leave it at that */
/* Put the x axis descriptor */
if ((pltlegend))
pgp_legend(gdsc, 1, 1, legend);
/* Plot everything */
for (i = 1; i < nrplts; ++i) {
def = 2;
nel = 1;
/* Inquire colour */
colour = i;
sprintf(inqstr, "GR_COL_%i=", i);
sprintf(mes, "Give Colour of plot %i", i);
userint_tir(startinfv -> arel, &colour, &nel, &def, inqstr, mes);
/* Inquire symbol */
symb = -1;
sprintf(inqstr, "GR_SYMB_%i=", i);
sprintf(mes, "Give symbol for plot %i", i);
userint_tir(startinfv -> arel, &symb, &nel, &def, inqstr, mes);
/* Inquire fill */
fill = 0;
/* sprintf(inqstr, "GR_EMTY_%i=", i); */
/* sprintf(mes, "Fill symbol for plot %i? (0)", i); */
/* userint_tir(startinfv -> arel, &fill, &nel, &def, inqstr, mes); */
/* Inquire sizer */
sizer = 1.0;
sprintf(inqstr, "GR_SIZE_%i=", i);
sprintf(mes, "Relative size of symbol for plot %i? (0)", i);
userreal_tir(startinfv -> arel, &sizer, &nel, &def, inqstr, mes);
/* Inquire lines */
lines = 0;
sprintf(inqstr, "GR_LINES_%i=", i);
sprintf(mes, "Plot lines 1/0? [0]");
userint_tir(startinfv -> arel, &lines, &nel, &def, inqstr, mes);
/* Inquire lines interpolation type */
switch (rpm -> smothcar[ident-1+NPARAMS-NDPARAMS]) {
case PGP_I_CSPLINE:
interp = 1;
break;
case PGP_I_AKIMA:
interp = 2;
break;
default:
interp = 0;
break;
}
sprintf(inqstr, "GR_INTERP_%i=", i);
sprintf(mes, "Interpolation 0: linear, 1: cubic spline, 2: Akima [0]");
userint_tir(startinfv -> arel, &interp, &nel, &def, inqstr, mes);
switch (interp) {
case 1:
interp = PGP_I_CSPLINE;
break;
case 2:
interp = PGP_I_AKIMA;
break;
default:
interp = PGP_I_LINEAR;
break;
}
/* Inqurie number of small interpolating lines, once for all */
gdsc -> interp_numlines = GR_INTERP_NUMLINES_DEFAULT;
sprintf(inqstr, "GR_INTERP_NUMLINES=");
sprintf(mes, "Number of small straight lines when interpolating [%i]", gdsc -> interp_numlines);
userint_tir(startinfv -> arel, &(gdsc -> interp_numlines), &nel, &def, inqstr, mes);
/* Inquire errorbars */
errbars = 0;
sprintf(inqstr, "GR_ERRB_%i=", i);
sprintf(mes, "Plot errorbars 1/0? [0]");
userint_tir(startinfv -> arel, &errbars, &nel, &def, inqstr, mes);
/* Inquire logarithmic scaling */
ylog = 0;
sprintf(inqstr, "GR_YLOG_%i=", i);
sprintf(mes, "y-axis logarithmic scaling 1/0? [0]");
userint_tir(startinfv -> arel, &ylog, &nel, &def, inqstr, mes);
if ((ylog))
ylog = 1;
/* Get number of vertical lines */
verln = 0;
nel = 1;
sprintf(inqstr, "GR_VERL_%i=", i);
sprintf(mes, "How many vertical lines for plot %i?", i);
userint_tir(startinfv -> arel, &verln, &nel, &def, inqstr, mes);
verln = verln > 0 ? verln : -verln;
if ((verln)) {
/* allocate */
if (!(vertarray = (float *) malloc(verln*sizeof(float))))
goto error;
if (!(vertcarray = (int *) malloc(verln*sizeof(int))))
goto error;
for (j = 0; j < verln; ++j)
vertarray[j] = 0.0;
for (j = 0; j < verln; ++j)
vertcarray[j] = 1;
sprintf(mes, "Give values for vertical lines");
def = 2;
nel = verln;
sprintf(inqstr, "GR_VLVA_%i=", i);
userreal_tir(startinfv -> arel, vertarray, &nel, &def, inqstr, mes);
sprintf(mes, "Give colours for vertical lines");
def = 2;
nel = verln;
sprintf(inqstr, "GR_VLCA_%i=", i);
userint_tir(startinfv -> arel, vertcarray, &nel, &def, inqstr, mes);
for (j = 0; j < verln; ++j)
vertcarray[j] = vertcarray[j] > 0 ? vertcarray[j] : - vertcarray[j];
}
/* Get number of horizontal lines */
horln = 0;
nel = 1;
sprintf(inqstr, "GR_HORL_%i=", i);
sprintf(mes, "How many horizontal lines for plot %i?", i);
userint_tir(startinfv -> arel, &horln, &nel, &def, inqstr, mes);
horln = horln > 0 ? horln : -horln;
if ((horln)) {
/* allocate */
if (!(horarray = (float *) malloc(horln*sizeof(float))))
goto error;
if (!(horcarray = (int *) malloc(horln*sizeof(int))))
goto error;
for (j = 0; j < horln; ++j)
horarray[j] = 0.0;
for (j = 0; j < horln; ++j)
horcarray[j] = 1;
sprintf(mes, "Give values for horizontal lines of plot %i",i);
sprintf(inqstr, "GR_HLVA_%i=", i);
def = 2;
nel = horln;
userreal_tir(startinfv -> arel, horarray, &nel, &def, inqstr, mes);
sprintf(mes, "Give colours for horizontal lines of plot %i", i);
def = 2;
nel = horln;
sprintf(inqstr, "GR_HLCA_%i=", i);
userint_tir(startinfv -> arel, horcarray, &nel, &def, inqstr, mes);
for (j = 0; j < verln; ++j)
horcarray[j] = horcarray[j] > 0 ? horcarray[j] : - horcarray[j];
}
/* Fill yerrarray */
if ((errbars)) {
/* We read all values into the outarray */
tir_get_radius(log, rpm, log -> outarray);
for (j = 0; j < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++j)
rpm -> par[j] = log -> outarray[j];
fillgrapharray(startinfv, hdr, rpm, ident, yerrarray, ylarray, rpm -> ndisks);
/* Give the user the possibility to put own errorbars */
def = 2;
nel = rpm -> nur;
sprintf(mes, "Give own errorbars");
sprintf(inqstr, "GR_ERRV_%i=", i);
userreal_tir(startinfv -> arel, yerrarray, &nel, &def, inqstr, mes);
}
else {
for (j = 0; j < rpm -> nur; ++j)
yerrarray[j] = 0;
}
/* Fill yarray */
/* We read all values into the outarray */
tir_get_grid(log, rpm, log -> outarray);
for (j = 0; j < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++j)
rpm -> par[j] = log -> outarray[j];
/* Central coordinates get the head cut off */
/* for (j = 0; j < rpm -> nur; ++j) { */
/* rpm -> par[PXPOS*rpm -> nur+j] = rpm -> par[PXPOS*rpm -> nur+j]-((int) rpm -> par[(PXPOS+1)*rpm -> nur-1]); */
/* rpm -> par[PYPOS*rpm -> nur+j] = rpm -> par[PYPOS*rpm -> nur+j]-((int) rpm -> par[(PYPOS+1)*rpm -> nur-1]); */
/* } */
fillgrapharray(startinfv, hdr, rpm, ident = get_graphident(varystr[i], NULL, NULL, NULL, NULL, rpm -> ndisks), yarray, ylarray, rpm -> ndisks);
/* Inquire number of additional arrays */
sprintf(mes, "Give number of additional rows for plot %i: [0]", i);
sprintf(inqstr, "GR_NRAD_%i=", i);
def = 2;
nel = 1;
nradd = 0;
userint_tir(startinfv -> arel, &nradd, &nel, &def, inqstr, mes);
/* Reserve memory */
if (nradd > 0) {
if (!(npadd = (int *) malloc(nradd*sizeof(int))))
goto error;
if (!(erad = (int *) malloc(nradd*sizeof(int))))
goto error;
if (!(adcol = (int *) malloc(nradd*sizeof(int))))
goto error;
if (!(adsymb = (int *) malloc(nradd*sizeof(int))))
goto error;
if (!(adfill = (int *) malloc(nradd*sizeof(int))))
goto error;
if (!(adlines = (int *) malloc(nradd*sizeof(int))))
goto error;
if (!(adinterp = (int *) malloc(nradd*sizeof(int))))
goto error;
if (!(adsizer = (float *) malloc(nradd*sizeof(float))))
goto error;
if (!(xval = (float **) malloc(nradd*sizeof(float *))))
goto error;
for (k = 0; k < nradd; ++k) {
xval[k] = NULL;
}
if (!(yval = (float **) malloc(nradd*sizeof(float *))))
goto error;
for (k = 0; k < nradd; ++k) {
yval[k] = NULL;
}
if (!(errb = (float **) malloc(nradd*sizeof(float *))))
goto error;
for (k = 0; k < nradd; ++k) {
errb[k] = NULL;
}
}
/* Now get the info about all the additional points */
for (k = 0; k < nradd; ++k) {
/* Inquire number of additional points */
sprintf(mes, "Give number of additional points for plot %i (%i): [0]", i, k+1);
sprintf(inqstr, "GR_NPAD_%i_%i=", i, k+1);
npadd[k] = -1;
while(npadd[k] < 0) {
def = 4;
nel = 1;
npadd[k] = 0;
userint_tir(startinfv -> arel, npadd+k, &nel, &def, inqstr, mes);
if (npadd[k] < 0) {
sprintf(mes, "Must be at least 0");
anyout_tir(&nel, mes);
cancel_tir(startinfv -> arel, inqstr, 2);
}
}
if ((npadd[k])) {
/* Reserve memory */
if (!(xval[k] = (float *) malloc(npadd[k]*sizeof(float))))
goto error;
if (!(yval[k] = (float *) malloc(npadd[k]*sizeof(float))))
goto error;
if (!(errb[k] = (float *) malloc(npadd[k]*sizeof(float))))
goto error;
/* Inquire points */
sprintf(mes, "Give additional points, x axis for plot %i (%i):", i, k+1);
sprintf(inqstr, "GR_XPAD_%i_%i=", i, k+1);
def = 4;
nel = npadd[k];
userreal_tir(startinfv -> arel, xval[k], &nel, &def, inqstr, mes);
sprintf(mes, "Give additional points, y axis for plot %i (%i):", i, k+1);
sprintf(inqstr, "GR_YPAD_%i_%i=", i, k+1);
userreal_tir(startinfv -> arel, yval[k], &nel, &def, inqstr, mes);
/* Inquire errorbars */
sprintf(mes, "Errorbars to additional points of plot %i (%i) (1/0)?", i, k+1);
sprintf(inqstr, "GR_ERAD_%i_%i=", i, k+1);
def = 2;
nel = 1;
erad[k] = 0;
userint_tir(startinfv -> arel, &erad[k], &nel, &def, inqstr, mes);
if ((erad[k])) {
/* Get the errorbars */
sprintf(mes, "Give errorbars for additional points of plot %i (%i):", i, k+1);
sprintf(inqstr, "GR_EBAD_%i_%i=", i, k+1);
def = 4;
nel = npadd[k];
userreal_tir(startinfv -> arel, errb[k], &nel, &def, inqstr, mes);
}
else {
for (j = 0; j < npadd[k]; ++j)
(errb[k])[j] = 0;
}
/* Inquire colour */
sprintf(mes, "Give colour of additional points of plot %i (%i):", i, k+1);
sprintf(inqstr, "GR_COAD_%i_%i", i, k+1);
def = 2;
nel = 1;
adcol[k] = i;
userint_tir(startinfv -> arel, adcol+k, &nel, &def, inqstr, mes);
/* Inquire symbol */
sprintf(mes, "Give symbol of additional points of plot %i (-1):", i);
sprintf(inqstr, "GR_SYAD_%i_%i", i, k+1);
def = 2;
nel = 1;
adsymb[k] = -1;
userint_tir(startinfv -> arel, adsymb+k, &nel, &def, inqstr, mes);
/* Inquire emptyness */
sprintf(mes, "Symbols of additional points of plot %i empty: (1)", i);
sprintf(inqstr, "GR_EMAD_%i_%i", i, k+1);
def = 2;
nel = 1;
adfill[k] = 0;
/* userint_tir(startinfv -> arel, adfill+k, &nel, &def, inqstr, mes); */
/* Inquire sizer */
sprintf(mes, "Size of additional points relative to standard size");
sprintf(inqstr, "GR_SIAD_%i_%i", i, k+1);
def = 2;
nel = 1;
adsizer[k] = 1.0;
userreal_tir(startinfv -> arel, adsizer+k, &nel, &def, inqstr, mes);
/* Inquire lines */
sprintf(mes, "Draw lines between additional points of plot %i (%i) (1/0)?", i, k+1);
sprintf(inqstr, "GR_LIAD_%i_%i", i, k+1);
def = 2;
nel = 1;
adlines[k] = 0;
userint_tir(startinfv -> arel, adlines+k, &nel, &def, inqstr, mes);
switch (interp) {
case PGP_I_CSPLINE:
adinterp[k] = 1;
break;
case PGP_I_AKIMA:
adinterp[k] = 2;
break;
default:
adinterp[k] = 0;
break;
}
/***/
/***/
/***/
/* fprintf(stderr,"Got here"); */
/***/
sprintf(inqstr, "GR_INTERPAD_%i_%i=", i, k+1);
sprintf(mes, "Interpolation between additional points plot %i (%i), 0: linear, 1: cubic spline, 2: Akima [0]", i, k+1);
userint_tir(startinfv -> arel, adinterp+k, &nel, &def, inqstr, mes);
switch (adinterp[k]) {
case 1:
adinterp[k] = PGP_I_CSPLINE;
break;
case 2:
adinterp[k] = PGP_I_AKIMA;
break;
default:
adinterp[k] = PGP_I_LINEAR;
break;
}
}
}
/* Inquire min and max */
ymin = yarray[0]-fabs(yerrarray[0]);
for (j = 1; j < rpm -> nur; ++j)
ymin = (ymin > (yarray[j]-fabs(yerrarray[j])))?(yarray[j]-fabs(yerrarray[j])):ymin;
if ((bars))
for (j = 0; j < rpm -> nr; ++j)
ymin = (ymin > ylarray[j])?ylarray[j]:ymin;
for (k = 0; k < nradd; ++k) {
for (j = 0; j < npadd[k]; ++j)
ymin = (ymin > ((yval[k])[j]-fabs((errb[k])[j])))?((yval[k])[j]-fabs((errb[k])[j])):ymin;
}
ymax = yarray[0]+fabs(yerrarray[0]);
for (j = 1; j < rpm -> nur; ++j)
ymax = (ymax < (yarray[j]+fabs(yerrarray[j])))?(yarray[j]+fabs(yerrarray[j])):ymax;
if ((bars))
for (j = 0; j < rpm -> nr; ++j)
ymax = (ymax < ylarray[j])?ylarray[j]:ymax;
for (k = 0; k < nradd; ++k) {
for (j = 0; j < npadd[k]; ++j)
ymax = (ymax < ((yval[k])[j]+fabs((errb[k])[j])))?((yval[k])[j]+fabs((errb[k])[j])):ymax;
}
/* Ask */
sprintf(inqstr, "GR_YMIN_%i=", i);
sprintf(mes, "Give minimum of y-axis %i: [%f]", i, ymin);
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &ymin, &nel, &def, inqstr, mes);
sprintf(inqstr, "GR_YMAX_%i=", i);
sprintf(mes, "Give maximum of y-axis %i: [%f]", i, ymax);
def = 2;
nel = 1;
userreal_tir(startinfv -> arel, &ymax, &nel, &def, inqstr, mes);
/* Fill the y axis descriptors and scalings */
/* Get the scale and the identity card */
gr_fillscaling(log, hdr, get_graphident(varystr[i], leftdeschi, leftdesclo, rightdesclo, legend, rpm -> ndisks), &lrscale, &lrzero, rpm -> ndisks);
/* In case of SBR, the right hand is SD */
if (ident == SBR)
gr_fillaxis((NPARAMS+(rpm -> ndisks-1)*NDPARAMS+DENS_GRAPHNR), rightdeschi, rpm -> ndisks);
else if (ident == XPOS) {
gr_fillaxis((NPARAMS+(rpm -> ndisks-1)*NDPARAMS+RASH_GRAPHNR), rightdeschi, rpm -> ndisks);
ylog = 2;
}
else if (ident == YPOS) {
gr_fillaxis((NPARAMS+(rpm -> ndisks-1)*NDPARAMS+DESH_GRAPHNR), rightdeschi, rpm -> ndisks);
ylog = 3;
}
else
gr_fillaxis(ident, rightdeschi, rpm -> ndisks);
/* Plot the box */
pgp_openbox(gdsc, i, xmin, xmax, ymin, ymax, leftdeschi, leftdesclo, rightdeschi, rightdesclo, bottomdeschi, bottomdesclo, topdeschi, topdesclo, lrzero, lrscale, btzero, btscale, xlog, ylog);
/* Plot additional points */
if (nradd > 0) {
for (k = 0; k < nradd; ++k) {
if ((npadd[k])) {
pgp_marker(gdsc, npadd[k], xval[k], yval[k], adcol[k], adfill[k], adsymb[k], adsizer[k]);
/* Plot errorbars */
if ((erad[k]))
pgp_errby(gdsc, npadd[k], xval[k], yval[k], errb[k], adcol[k]);
/* Plot lines */
if ((adlines[k])) {
gdsc -> interptype_lines = adinterp[k];
pgp_lines(gdsc, npadd[k], xval[k], yval[k], adcol[k]);
}
/* Free memory */
free(xval[k]);
xval[k] = NULL;
free(yval[k]);
yval[k] = NULL;
free(errb[k]);
errb[k] = NULL;
}
}
/* free stuff */
free(npadd);
free(erad);
free(adcol);
free(adlines);
free(xval);
free(yval);
free(errb);
}
/* Plot bars */
if ((bars))
pgp_bars(gdsc, rpm -> nr, xlarray, ylarray, barwidth, colour);
/* Plot lines */
if ((lines)) {
gdsc -> interptype_lines = interp;
pgp_lines(gdsc, rpm -> nur, xarray, yarray, colour);
}
/* Copy the x array and remove points */
for (j = 0; j < rpm -> nur; ++j)
xarray2[j] = xarray[j];
numplpts = gr_deleteindexed(rpm -> nur, ident, xarray2, yarray, yerrarray, fit -> index, rpm -> ndisks);
if (numplpts) {
/* Plot errorbars */
if ((errbars))
pgp_errby(gdsc, numplpts, xarray2, yarray, yerrarray, colour);
/* Plot the points */
pgp_marker(gdsc, numplpts, xarray2, yarray, colour, fill, symb, sizer);
}
/* plot horizontal lines */
if ((horln)) {
for (j = 0; j < horln; ++j) {
vhlys[0] = vhlys[1] = horarray[j];
if (xmin == xmax) {
vhlxs[0] = 1000000.0*xarray[0]+0.1;
vhlxs[1] = -1000000.0*xarray[0]-0.1;
}
else {
vhlxs[0] = (xmin+xmax)/2.0-1000000.0*(xmax-xmin);
vhlxs[1] = (xmin+xmax)/2.0+1000000.0*(xmax-xmin);
}
dummy = gdsc -> interptype_lines;
gdsc -> interptype_lines = PGP_I_LINEAR;
pgp_lines(gdsc, 2, vhlxs, vhlys, horcarray[j]);
gdsc -> interptype_lines = dummy;
}
free(horarray);
free(horcarray);
}
/* plot vertical lines */
if ((verln)) {
for (j = 0; j < verln; ++j) {
vhlxs[0] = vhlxs[1] = vertarray[j];
if (ymin == ymax) {
vhlys[0] = 1000000.0*yarray[0]+0.1;
vhlys[1] = -1000000.0*yarray[0]-0.1;
}
else {
vhlys[0] = (ymin+ymax)/2.0-1000000.0*(ymax-ymin);
vhlys[1] = (ymin+ymax)/2.0+1000000.0*(ymax-ymin);
}
/* Switch off interpolation scheme before plotting and reinstate */
dummy = gdsc -> interptype_lines;
gdsc -> interptype_lines = PGP_I_LINEAR;
pgp_lines(gdsc, 2, vhlxs, vhlys, vertcarray[j]);
gdsc -> interptype_lines = dummy;
}
free(vertarray);
free(vertcarray);
}
/* Put the legend line */
if ((pltlegend))
pgp_legend(gdsc, i%2+1, i/2+1, legend);
}
/* Free memory */
free(varystr);
free(varyhstr);
free(xarray);
free(xarray2);
free(yarray);
free(yerrarray);
free(xlarray);
free(ylarray);
free(pgdevice);
/* Once we got here, we ask the user if to continue */
sprintf(mes, "Continue (Press return)?");
def = 1;
nel = 1;
userint_tir(startinfv -> arel, &pltlegend, &nel, &def, "GR_CONT=", mes);
/* Then we stop it */
pgp_end();
return nrplts-1;
error:
if ((varystr))
free(varystr);
if ((varyhstr))
free(varyhstr);
if ((xarray))
free(xarray);
if ((xarray2))
free(xarray2);
if ((yarray))
free(yarray);
if ((yerrarray))
free(yerrarray);
if ((xlarray))
free(xlarray);
if ((ylarray))
free(ylarray);
if ((npadd))
free(npadd);
if ((erad))
free(erad);
if ((adcol))
free(adcol);
if ((adsymb))
free(adsymb);
if ((adfill))
free(adfill);
if ((adlines))
free(adlines);
if ((adsizer))
free(adsizer);
if ((vertarray))
free(vertarray);
if ((horarray))
free(horarray);
if ((vertcarray))
free(vertcarray);
if ((horcarray))
free(horcarray);
if ((xval)) {
for (i = 0; i < nradd; ++i) {
if ((xval[i]))
free(xval[i]);
}
free(xval);
}
if ((yval)) {
for (i = 0; i < nradd; ++i) {
if ((yval[i]))
free(yval[i]);
}
free(yval);
}
if ((errb)) {
for (i = 0; i < nradd; ++i) {
if ((errb[i]))
free(errb[i]);
}
free(errb);
}
if ((pgdevice))
free(pgdevice);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns the identifyer of a graphics output */
static int get_graphident(char *string, char *axis, char *unit, char *altunit, char *legend, int ndisks)
{
int ident;
/* First check if there is a string */
if (!string)
return -1;
/* Now check if it can be identified with a variable parameter itself */
if(((ident = ftstab_gtitln_(string)) <= 0))
ident = get_graphnr(string, ndisks);
else if (ident > (NPARAMS+(ndisks-1)*NDPARAMS))
return -1;
if (ident == 0)
return -1;
/* Now fill the strings */
gr_fillaxis(ident, axis, ndisks);
gr_fillunit(ident, unit, ndisks);
gr_fillaltunit(ident, altunit, ndisks);
gr_filllegend(ident, legend, ndisks);
/* Finis */
return ident;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Identifies a graphics output number */
static int get_graphnr(char *string, int ndisks)
{
if (!strcmp(string, "WA"))
return NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR;
if (!strcmp(string, "DENS"))
return NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR;
if (!strcmp(string, "WOLD"))
return NPARAMS+(ndisks-1)*NDPARAMS+WOLD_GRAPHNR;
if (!strcmp(string, "TIP"))
return NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR;
if (!strcmp(string, "LON"))
return NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR;
return -1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns an axis descriptor string suitable for the use in the pgp module */
static void gr_fillaxis(int ident, char *string, int ndisks)
{
int disk;
if ((string)) {
if (ident ==RADI) {
sprintf(string, "R");
return;
}
if (ident ==VROT) {
sprintf(string, "VROT");
return;
}
if (ident ==VRAD) {
sprintf(string, "VRAD");
return;
}
if (ident ==VVER) {
sprintf(string, "VVER");
return;
}
if (ident ==DVRO) {
sprintf(string, "DVRO");
return;
}
if (ident ==DVRA) {
sprintf(string, "DVRA");
return;
}
if (ident ==DVVE) {
sprintf(string, "DVVE");
return;
}
if (ident ==ZDRO) {
sprintf(string, "ZDRO");
return;
}
if (ident ==ZDRA) {
sprintf(string, "ZDRA");
return;
}
if (ident ==ZDVE) {
sprintf(string, "ZDVE");
return;
}
if (ident ==Z0) {
sprintf(string, "SCHT");
return;
}
if (ident ==SDIS) {
sprintf(string, "DISP");
return;
}
if (ident ==CLNR) {
sprintf(string, "CLNR");
return;
}
if (ident ==VM0A ) {
sprintf(string, "VM0A");
return;
}
if (ident ==VM1A) {
sprintf(string, "VM1A");
return;
}
if (ident ==VM1P) {
sprintf(string, "VM1P");
return;
}
if (ident ==VM2A) {
sprintf(string, "VM2A");
return;
}
if (ident ==VM2P) {
sprintf(string, "VM2P");
return;
}
if (ident ==VM3A) {
sprintf(string, "VM3A");
return;
}
if (ident ==VM3P) {
sprintf(string, "VM3P");
return;
}
if (ident ==VM4A) {
sprintf(string, "VM4A");
return;
}
if (ident ==VM4P) {
sprintf(string, "VM4P");
return;
}
if (ident ==RA1A) {
sprintf(string, "RA1A");
return;
}
if (ident ==RA1P) {
sprintf(string, "RA1P");
return;
}
if (ident ==RA2A) {
sprintf(string, "RA2A");
return;
}
if (ident ==RA2P) {
sprintf(string, "RA2P");
return;
}
if (ident ==RA3A) {
sprintf(string, "RA3A");
return;
}
if (ident ==RA3P) {
sprintf(string, "RA3P");
return;
}
if (ident ==RA4A) {
sprintf(string, "RA4A");
return;
}
if (ident ==RA4P) {
sprintf(string, "RA4P");
return;
}
if (ident ==RO1A) {
sprintf(string, "RO1A");
return;
}
if (ident ==RO1P) {
sprintf(string, "RO1P");
return;
}
if (ident ==RO2A) {
sprintf(string, "RO2A");
return;
}
if (ident ==RO2P) {
sprintf(string, "RO2P");
return;
}
if (ident ==RO3A) {
sprintf(string, "RO3A");
return;
}
if (ident ==RO3P) {
sprintf(string, "RO3P");
return;
}
if (ident ==RO4A) {
sprintf(string, "RO4A");
return;
}
if (ident ==RO4P) {
sprintf(string, "RO4P");
return;
}
if (ident ==WM0A ) {
sprintf(string, "WM0A");
return;
}
if (ident ==WM1A ) {
sprintf(string, "WM1A");
return;
}
if (ident ==WM1P ) {
sprintf(string, "WM1P");
return;
}
if (ident ==WM2A ) {
sprintf(string, "WM2A");
return;
}
if (ident ==WM2P ) {
sprintf(string, "WM2P");
return;
}
if (ident ==WM3A ) {
sprintf(string, "WM3A");
return;
}
if (ident ==WM3P ) {
sprintf(string, "WM3P");
return;
}
if (ident ==WM4A ) {
sprintf(string, "WM4A");
return;
}
if (ident ==WM4P ) {
sprintf(string, "WM4P");
return;
}
if (ident ==LS0 ) {
sprintf(string, "LS0");
return;
}
if (ident ==LC0 ) {
sprintf(string, "LC0");
return;
}
if (ident ==SBR) {
sprintf(string, "SBR");
return;
}
if (ident ==SM1A) {
sprintf(string, "SM1A");
return;
}
if (ident ==SM1P) {
sprintf(string, "SM1P");
return;
}
if (ident ==SM2A) {
sprintf(string, "SM2A");
return;
}
if (ident ==SM2P) {
sprintf(string, "SM2P");
return;
}
if (ident ==SM3A) {
sprintf(string, "SM3A");
return;
}
if (ident ==SM3P) {
sprintf(string, "SM3P");
return;
}
if (ident ==SM4A) {
sprintf(string, "SM4A");
return;
}
if (ident ==SM4P) {
sprintf(string, "SM4P");
return;
}
if (ident ==GA1A) {
sprintf(string, "GA1A");
return;
}
if (ident ==GA1P) {
sprintf(string, "GA1P");
return;
}
if (ident ==GA1D) {
sprintf(string, "GA1D");
return;
}
if (ident ==GA2A) {
sprintf(string, "GA2A");
return;
}
if (ident ==GA2P) {
sprintf(string, "GA2P");
return;
}
if (ident ==GA2D) {
sprintf(string, "GA2D");
return;
}
if (ident ==GA3A) {
sprintf(string, "GA3A");
return;
}
if (ident ==GA3P) {
sprintf(string, "GA3P");
return;
}
if (ident ==GA3D) {
sprintf(string, "GA3D");
return;
}
if (ident ==GA4A) {
sprintf(string, "GA4A");
return;
}
if (ident ==GA4P) {
sprintf(string, "GA4P");
return;
}
if (ident ==GA4D) {
sprintf(string, "GA4D");
return;
}
if (ident ==AZ1P) {
sprintf(string, "AZ1P");
return;
}
if (ident ==AZ1W) {
sprintf(string, "AZ1W");
return;
}
if (ident ==AZ2P) {
sprintf(string, "AZ2P");
return;
}
if (ident ==AZ2W) {
sprintf(string, "AZ2W");
return;
}
if (ident ==INCL) {
sprintf(string, "INCL");
return;
}
if (ident ==PA) {
sprintf(string, "PA");
return;
}
if (ident ==XPOS) {
sprintf(string, "RA");
return;
}
if (ident ==YPOS) {
sprintf(string, "DEC");
return;
}
if (ident ==VSYS) {
sprintf(string, "VSYS");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR)) {
sprintf(string, "WA");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR)) {
sprintf(string, "SD");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WOLD_GRAPHNR)) {
sprintf(string, "WAOL");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR)) {
sprintf(string, "TIP");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR)) {
sprintf(string, "LON");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DESH_GRAPHNR)) {
sprintf(string, "DESH");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+RASH_GRAPHNR)) {
sprintf(string, "RASH");
return;
}
for (disk = 1; disk < ndisks; ++disk) {
if (ident == VROT+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VROT_%i", disk+1); return; }
if (ident == VRAD+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VRAD_%i", disk+1); return; }
if (ident == VVER+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VVER_%i", disk+1); return; }
if (ident == DVRO+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DVRO_%i", disk+1); return; }
if (ident == DVRA+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DVRA_%i", disk+1); return; }
if (ident == DVVE+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DVVE_%i", disk+1); return; }
if (ident == ZDRO+PRPARAMS+disk*NDPARAMS) { sprintf(string, "ZDRO_%i", disk+1); return; }
if (ident == ZDRA+PRPARAMS+disk*NDPARAMS) { sprintf(string, "ZDRA_%i", disk+1); return; }
if (ident == ZDVE+PRPARAMS+disk*NDPARAMS) { sprintf(string, "ZDVE_%i", disk+1); return; }
if (ident == Z0 +PRPARAMS+disk*NDPARAMS) { sprintf(string, "SCHT_%i", disk+1); return; }
if (ident == SDIS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DISP_%i", disk+1); return; }
if (ident == CLNR+PRPARAMS+disk*NDPARAMS) { sprintf(string, "CLNR_%i", disk+1); return; }
if (ident == VM0A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM0A_%i", disk+1); return; }
if (ident == VM1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM1A_%i", disk+1); return; }
if (ident == VM1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM1P_%i", disk+1); return; }
if (ident == VM2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM2A_%i", disk+1); return; }
if (ident == VM2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM2P_%i", disk+1); return; }
if (ident == VM3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM3A_%i", disk+1); return; }
if (ident == VM3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM3P_%i", disk+1); return; }
if (ident == VM4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM4A_%i", disk+1); return; }
if (ident == VM4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM4P_%i", disk+1); return; }
if (ident == RA1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA1A_%i", disk+1); return; }
if (ident == RA1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA1P_%i", disk+1); return; }
if (ident == RA2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA2A_%i", disk+1); return; }
if (ident == RA2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA2P_%i", disk+1); return; }
if (ident == RA3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA3A_%i", disk+1); return; }
if (ident == RA3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA3P_%i", disk+1); return; }
if (ident == RA4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA4A_%i", disk+1); return; }
if (ident == RA4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA4P_%i", disk+1); return; }
if (ident == RO1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO1A_%i", disk+1); return; }
if (ident == RO1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO1P_%i", disk+1); return; }
if (ident == RO2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO2A_%i", disk+1); return; }
if (ident == RO2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO2P_%i", disk+1); return; }
if (ident == RO3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO3A_%i", disk+1); return; }
if (ident == RO3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO3P_%i", disk+1); return; }
if (ident == RO4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO4A_%i", disk+1); return; }
if (ident == RO4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO4P_%i", disk+1); return; }
if (ident == WM0A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM0A_%i", disk+1); return; }
if (ident == WM1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM1A_%i", disk+1); return; }
if (ident == WM1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM1P_%i", disk+1); return; }
if (ident == WM2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM2A_%i", disk+1); return; }
if (ident == WM2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM2P_%i", disk+1); return; }
if (ident == WM3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM3A_%i", disk+1); return; }
if (ident == WM3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM3P_%i", disk+1); return; }
if (ident == WM4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM4A_%i", disk+1); return; }
if (ident == WM4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "WM4P_%i", disk+1); return; }
if (ident == LS0 +PRPARAMS+disk*NDPARAMS) { sprintf(string, "LS0_%i", disk+1); return; }
if (ident == LC0 +PRPARAMS+disk*NDPARAMS) { sprintf(string, "LC0_%i", disk+1); return; }
if (ident == SBR +PRPARAMS+disk*NDPARAMS) { sprintf(string, "SBR_%i", disk+1); return; }
if (ident == SM1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM1P_%i", disk+1); return; }
if (ident == SM2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM2A_%i", disk+1); return; }
if (ident == SM2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM2P_%i", disk+1); return; }
if (ident == SM3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM3A_%i", disk+1); return; }
if (ident == SM3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM3P_%i", disk+1); return; }
if (ident == SM4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM4A_%i", disk+1); return; }
if (ident == SM4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM4P_%i", disk+1); return; }
if (ident == GA1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA1A_%i", disk+1); return; }
if (ident == GA1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA1P_%i", disk+1); return; }
if (ident == GA1D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA1D_%i", disk+1); return; }
if (ident == GA2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA2A_%i", disk+1); return; }
if (ident == GA2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA2P_%i", disk+1); return; }
if (ident == GA2D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA2D_%i", disk+1); return; }
if (ident == GA3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA3A_%i", disk+1); return; }
if (ident == GA3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA3P_%i", disk+1); return; }
if (ident == GA3D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA3D_%i", disk+1); return; }
if (ident == GA4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA4A_%i", disk+1); return; }
if (ident == GA4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA4P_%i", disk+1); return; }
if (ident == GA4D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA4D_%i", disk+1); return; }
if (ident == AZ1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ1P_%i", disk+1); return; }
if (ident == AZ1W+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ1W_%i", disk+1); return; }
if (ident == AZ2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ2P_%i", disk+1); return; }
if (ident == AZ2W+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ2W_%i", disk+1); return; }
if (ident == INCL+PRPARAMS+disk*NDPARAMS) { sprintf(string, "INCL_%i", disk+1); return; }
if (ident == PA +PRPARAMS+disk*NDPARAMS) { sprintf(string, "PA_%i", disk+1); return; }
if (ident == XPOS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "XPOS_%i", disk+1); return; }
if (ident == YPOS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "YPOS_%i", disk+1); return; }
if (ident == VSYS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VSYS_%i", disk+1); return; }
}
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns an unit string suitable for the use in the pgp module */
void gr_fillunit(int ident, char *string, int ndisks)
{
if ((string)) {
if (ident == RADI) {
sprintf(string, "arcsec");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR)) {
sprintf(string, "degree");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR)) {
sprintf(string, "cm\\u-2");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WOLD_GRAPHNR)) {
sprintf(string, "degree");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR)) {
sprintf(string, "degree");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR)) {
sprintf(string, "degree");
return;
}
ident = (ident-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS + 1;
switch (ident) {
case VROT:
sprintf(string, "km\\.s\\u-1");
return;
case VRAD:
sprintf(string, "km\\.s\\u-1");
return;
case VVER:
sprintf(string, "km\\.s\\u-1");
return;
case DVRO:
sprintf(string, "km\\.s\\u-1\\d\\.arcsec\\u-1");
return;
case DVRA:
sprintf(string, "km\\.s\\u-1\\d\\.arcsec\\u-1");
return;
case DVVE:
sprintf(string, "km\\.s\\u-1\\d\\.arcsec\\u-1");
return;
case ZDRO:
sprintf(string, "arcsec");
return;
case ZDRA:
sprintf(string, "arcsec");
return;
case ZDVE:
sprintf(string, "arcsec");
return;
case Z0:
sprintf(string, "arcsec");
return;
case SDIS:
sprintf(string, "km\\.s\\u-1");
return;
case CLNR:
sprintf(string, " ");
return;
case VM0A :
sprintf(string, "km\\.s\\u-1");
return;
case VM1A:
sprintf(string, "km\\.s\\u-1");
return;
case VM1P:
sprintf(string, "degree");
return;
case VM2A:
sprintf(string, "km\\.s\\u-1");
return;
case VM2P:
sprintf(string, "degree");
return;
case VM3A:
sprintf(string, "km\\.s\\u-1");
return;
case VM3P:
sprintf(string, "degree");
return;
case VM4A:
sprintf(string, "km\\.s\\u-1");
return;
case VM4P:
sprintf(string, "degree");
return;
case RA1A:
sprintf(string, "km\\.s\\u-1");
return;
case RA1P:
sprintf(string, "degree");
return;
case RA2A:
sprintf(string, "km\\.s\\u-1");
return;
case RA2P:
sprintf(string, "degree");
return;
case RA3A:
sprintf(string, "km\\.s\\u-1");
return;
case RA3P:
sprintf(string, "degree");
return;
case RA4A:
sprintf(string, "km\\.s\\u-1");
return;
case RA4P:
sprintf(string, "degree");
return;
case RO1A:
sprintf(string, "km\\.s\\u-1");
return;
case RO1P:
sprintf(string, "degree");
return;
case RO2A:
sprintf(string, "km\\.s\\u-1");
return;
case RO2P:
sprintf(string, "degree");
return;
case RO3A:
sprintf(string, "km\\.s\\u-1");
return;
case RO3P:
sprintf(string, "degree");
return;
case RO4A:
sprintf(string, "km\\.s\\u-1");
return;
case RO4P:
sprintf(string, "degree");
return;
case WM0A :
sprintf(string, "arcsec");
return;
case WM1A :
sprintf(string, "arcsec");
return;
case WM1P :
sprintf(string, "degree");
return;
case WM2A :
sprintf(string, "arcsec");
return;
case WM2P :
sprintf(string, "degree");
return;
case WM3A :
sprintf(string, "arcsec");
return;
case WM3P :
sprintf(string, "degree");
return;
case WM4A :
sprintf(string, "arcsec");
return;
case WM4P :
sprintf(string, "degree");
return;
case LS0 :
sprintf(string, "arcsec");
return;
case LC0 :
sprintf(string, "arcsec");
return;
case SBR:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case SM1A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case SM1P:
sprintf(string, "degree");
return;
case SM2A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case SM2P:
sprintf(string, "degree");
return;
case SM3A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case SM3P:
sprintf(string, "degree");
return;
case SM4A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case SM4P:
sprintf(string, "degree");
return;
case GA1A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case GA1P:
sprintf(string, "degree");
return;
case GA1D:
sprintf(string, "arcsec");
return;
case GA2A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case GA2P:
sprintf(string, "degree");
return;
case GA2D:
sprintf(string, "arcsec");
return;
case GA3A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case GA3P:
sprintf(string, "degree");
return;
case GA3D:
sprintf(string, "arcsec");
return;
case GA4A:
sprintf(string, "Jy\\.km\\.s\\u-1\\d\\.arcsec\\u-2");
return;
case GA4P:
sprintf(string, "degree");
return;
case GA4D:
sprintf(string, "arcsec");
return;
case AZ1P:
sprintf(string, "degree");
return;
case AZ1W:
sprintf(string, "degree");
return;
case AZ2P:
sprintf(string, "degree");
return;
case AZ2W:
sprintf(string, "degree");
return;
case INCL:
sprintf(string, "degree");
return;
case PA:
sprintf(string, "degree");
return;
case XPOS:
sprintf(string, "hh mm ss.s");
return;
case YPOS:
sprintf(string, "dd mm ss.s");
return;
case VSYS:
sprintf(string, "km\\.s\\u-1");
return;
}
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns an alternative unit string suitable for the use in the pgp module */
static void gr_fillaltunit(int ident, char *string, int ndisks)
{
if ((string)) {
if (ident == RADI) {
sprintf(string, "kpc");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR)) {
sprintf(string, "degree");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR)) {
sprintf(string, "M\\d\\(2281)\\u\\.pc\\u-2");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WOLD_GRAPHNR)) {
sprintf(string, "degree");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR)) {
sprintf(string, "degree");
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR)) {
sprintf(string, "degree");
return;
}
ident = (ident-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS + 1;
switch (ident) {
case VROT:
sprintf(string, "km\\.s\\u-1");
return;
case VRAD:
sprintf(string, "km\\.s\\u-1");
return;
case VVER:
sprintf(string, "km\\.s\\u-1");
return;
case DVRO:
sprintf(string, "km\\.s\\u-1\\d\\.pc\\u-1");
return;
case DVRA:
sprintf(string, "km\\.s\\u-1\\d\\.pc\\u-1");
return;
case DVVE:
sprintf(string, "km\\.s\\u-1\\d\\.pc\\u-1");
return;
case ZDRA:
sprintf(string, "pc");
return;
case ZDRO:
sprintf(string, "pc");
return;
case ZDVE:
sprintf(string, "pc");
return;
case Z0:
sprintf(string, "pc");
return;
case SDIS:
sprintf(string, "km\\.s\\u-1");
return;
case CLNR:
sprintf(string, " ");
return;
case VM0A :
sprintf(string, "km\\.s\\u-1");
return;
case VM1A:
sprintf(string, "km\\.s\\u-1");
return;
case VM1P:
sprintf(string, "degree");
return;
case VM2A:
sprintf(string, "km\\.s\\u-1");
return;
case VM2P:
sprintf(string, "degree");
return;
case VM3A:
sprintf(string, "km\\.s\\u-1");
return;
case VM3P:
sprintf(string, "degree");
return;
case VM4A:
sprintf(string, "km\\.s\\u-1");
return;
case VM4P:
sprintf(string, "degree");
return;
case RA1A:
sprintf(string, "km\\.s\\u-1");
return;
case RA1P:
sprintf(string, "degree");
return;
case RA2A:
sprintf(string, "km\\.s\\u-1");
return;
case RA2P:
sprintf(string, "degree");
return;
case RA3A:
sprintf(string, "km\\.s\\u-1");
return;
case RA3P:
sprintf(string, "degree");
return;
case RA4A:
sprintf(string, "km\\.s\\u-1");
return;
case RA4P:
sprintf(string, "degree");
return;
case RO1A:
sprintf(string, "km\\.s\\u-1");
return;
case RO1P:
sprintf(string, "degree");
return;
case RO2A:
sprintf(string, "km\\.s\\u-1");
return;
case RO2P:
sprintf(string, "degree");
return;
case RO3A:
sprintf(string, "km\\.s\\u-1");
return;
case RO3P:
sprintf(string, "degree");
return;
case RO4A:
sprintf(string, "km\\.s\\u-1");
return;
case RO4P:
sprintf(string, "degree");
return;
case WM0A :
sprintf(string, "pc");
return;
case WM1A :
sprintf(string, "pc");
return;
case WM1P :
sprintf(string, "degree");
return;
case WM2A :
sprintf(string, "pc");
return;
case WM2P :
sprintf(string, "degree");
return;
case WM3A :
sprintf(string, "pc");
return;
case WM3P :
sprintf(string, "degree");
return;
case WM4A :
sprintf(string, "pc");
return;
case WM4P :
sprintf(string, "degree");
return;
case LS0 :
sprintf(string, "pc");
return;
case LC0 :
sprintf(string, "pc");
return;
case SBR:
sprintf(string, "cm\\u-2");
return;
case SM1A:
sprintf(string, "cm\\u-2");
return;
case SM1P:
sprintf(string, "degree");
return;
case SM2A:
sprintf(string, "cm\\u-2");
return;
case SM2P:
sprintf(string, "degree");
return;
case SM3A:
sprintf(string, "cm\\u-2");
return;
case SM3P:
sprintf(string, "degree");
return;
case SM4A:
sprintf(string, "cm\\u-2");
return;
case SM4P:
sprintf(string, "degree");
return;
case GA1A:
sprintf(string, "cm\\u-2");
return;
case GA1P:
sprintf(string, "degree");
return;
case GA1D:
sprintf(string, "pc");
return;
case GA2A:
sprintf(string, "cm\\u-2");
return;
case GA2P:
sprintf(string, "degree");
return;
case GA2D:
sprintf(string, "pc");
return;
case GA3A:
sprintf(string, "cm\\u-2");
return;
case GA3P:
sprintf(string, "degree");
return;
case GA3D:
sprintf(string, "pc");
return;
case GA4A:
sprintf(string, "cm\\u-2");
return;
case GA4P:
sprintf(string, "degree");
return;
case GA4D:
sprintf(string, "pc");
return;
case AZ1P:
sprintf(string, "degree");
return;
case AZ1W:
sprintf(string, "degree");
return;
case AZ2P:
sprintf(string, "degree");
return;
case AZ2W:
sprintf(string, "degree");
return;
case INCL:
sprintf(string, "rad");
return;
case PA:
sprintf(string, "rad");
return;
case XPOS:
sprintf(string, "kpc");
return;
case YPOS:
sprintf(string, "kpc");
return;
case VSYS:
sprintf(string, "km\\.s\\u-1");
return;
}
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* */
static int gr_deleteindexed(int nur, int ident, float *xarray, float *yarray, float *yerrarray, decomp_inlist *index, int ndisks)
{
int i = 0, j , k, l, m, ident2;
ident2 = ident;
if (ident > 0) {
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR) || ident == (NPARAMS+(ndisks-1)*NDPARAMS+WOLD_GRAPHNR) || ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR) || ident == (NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR)) {
ident = PA;
ident2 = INCL;
}
else if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR)){
ident = ident2 = SBR;
}
}
l = nur;
for (i = 0; i < nur; ++i) {
for (m = 0; m < index -> nuel; ++m) {
if ((ident-1)*nur+i == index -> ipa[m]) {
for (j = 0; j < index -> nuel; ++j) {
if ((ident2-1)*nur+i == index -> ipa[j]) {
for (k = i-nur+l+1; k < nur; ++k) {
xarray[k-1] = xarray[k];
yarray[k-1] = yarray[k];
yerrarray[k-1] = yerrarray[k];
}
--l;
m = index -> nuel;
break;
}
}
}
}
}
return l;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Fills two arrays for graphics use */
static int fillgrapharray(startinf *startinfv, hdrinf *hdr, ringparms *rpm, int ident, float *array, float *larray, int ndisks)
{
int i, j;
int def = 2;
int nel = 1;
int rring = 5;
int err = 1;
int gr_tlr = 0;
char mes[81];
double br_incl;
double br_pa;
double gr_tll;
double nv[3];
double nrefr[3];
double value;
double vsys, nu;
double rescval;
double x,y;
/* Check if it can be done */
if (ident > 0) {
if (ident <= (NPARAMS+(ndisks-1)*NDPARAMS)) {
/* Simply put the values into the arrays */
for (i = 0; i < rpm -> nur; ++i)
array[i] = rpm -> par[(ident-1)*rpm -> nur+i];
for (i = 0; i < rpm -> nr; ++i)
larray[i] = rpm -> modpar[(ident-1)*rpm -> nr+i];
}
else if (ident == (NPARAMS+(rpm -> ndisks-1)*NDPARAMS+WA_GRAPHNR) || ident == (NPARAMS+(rpm -> ndisks-1)*NDPARAMS+WOLD_GRAPHNR)) {
if (ident == (NPARAMS+(rpm -> ndisks-1)*NDPARAMS+WA_GRAPHNR)) {
/* Calculate the normal vector of the reference */
for (i = 0; i < 3; ++i) {
nrefr[i] = 0;
}
/* Now we calculate the direction of the total angular momentum of the observed component */
for (j = 0; j < rpm -> nr; ++j) {
/* We don't do a relativistic correction for this */
value = pow(rpm -> modpar[PRADI*rpm -> nr+j],2)*rpm -> modpar[PVROT*rpm -> nr+j]*rpm -> modpar[PSBR*rpm -> nr+j];
nrefr[0] = nrefr[0]+(double) value*sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*sin(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nrefr[1] = nrefr[1]-(double) value*sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*cos(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nrefr[2] = nrefr[2]+(double) value*cos(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j]);
}
value = sqrt(pow(nrefr[0],2)+pow(nrefr[1],2)+pow(nrefr[2],2));
nrefr[0] = nrefr[0]/value;
nrefr[1] = nrefr[1]/value;
nrefr[2] = nrefr[2]/value;
}
else {
/* Get the reference ring */
sprintf(mes, "Give reference ring for warp angle calculation");
while ((err)) {
userint_tir(startinfv -> arel, &rring, &nel, &def, "REFRING=", mes);
if (rring <= 0 || rring > rpm -> nur) {
sprintf(mes, "REFRING: impossible number");
cancel_tir(startinfv -> arel, "REFRING=", 2);
def = 4;
}
else
err = 0;
}
/* Now get the normal vector of the reference ring */
nrefr[0] = sinf(DEGTORAD*rpm -> par[PINCL*rpm -> nur+rring-1])*sinf(DEGTORAD*rpm -> par[PPA*rpm -> nur+rring-1]);
nrefr[1] = -sinf(DEGTORAD*rpm -> par[PINCL*rpm -> nur+rring-1])*cosf(DEGTORAD*rpm -> par[PPA*rpm -> nur+rring-1]);
nrefr[2] = cosf(DEGTORAD*rpm -> par[PINCL*rpm -> nur+rring-1]);
}
/* Now calculate the inclination of the rings with the refring */
for (j = 0; j < rpm -> nur; ++j) {
nv[0] = sin(DEGTORAD*rpm -> par[PINCL*rpm -> nur+j])*sin(DEGTORAD*rpm -> par[PPA*rpm -> nur+j]);
nv[1] = -sin(DEGTORAD*rpm -> par[PINCL*rpm -> nur+j])*cos(DEGTORAD*rpm -> par[PPA*rpm -> nur+j]);
nv[2] = cos(DEGTORAD*rpm -> par[PINCL*rpm -> nur+j]);
/* Here is the scalar product with the reference ring */
value = nv[0]*nrefr[0]+nv[1]*nrefr[1]+nv[2]*nrefr[2];
/* This is the arcus */
array[j] = value>1?0.0:RADTODEG*acos(value);
}
/* Now calculate the inclination of the subrings with the refring */
for (j = 0; j < rpm -> nr; ++j) {
nv[0] = sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*sin(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nv[1] = -sin(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j])*cos(DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j]);
nv[2] = cos(DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j]);
/* Here is the scalar product with the reference ring */
value = nv[0]*nrefr[0]+nv[1]*nrefr[1]+nv[2]*nrefr[2];
/* This is the arcus */
larray[j] = value>1?0.0:RADTODEG*acos(value);
}
}
else if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR)){
/* We do it properly */
for (j = 0; j < rpm -> nur; ++j) {
vsys = rpm -> par[PVSYS*rpm -> nur+j];
nu = (SPEEDOFLIGHT-vsys)*HIRESFREQ/SPEEDOFLIGHT;
value = rpm -> par[PSBR*rpm -> nur+j];
/* The intensity in the restframe scales like */
array[j] = hdr -> itou*value*pow(HIRESFREQ/nu,4);
}
for (j = 0; j < rpm -> nr; ++j) {
vsys = rpm -> modpar[PVSYS*rpm -> nr+j];
nu = (SPEEDOFLIGHT-vsys)*HIRESFREQ/SPEEDOFLIGHT;
value = rpm -> modpar [PSBR*rpm -> nr+j];
/* The intensity in the restframe scales like */
larray[j] = hdr -> itou*value*pow(HIRESFREQ/nu,4);
}
}
else if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR) || ident == (NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR)) {
/* Ask for the reference position angle, default 0 */
sprintf(mes, "Give Briggs reference position angle");
br_pa = 0;
def = 2;
nel = 1;
userdble_tir(startinfv -> arel, &br_pa, &nel, &def, "BR_PA=", mes);
/* Ask for the reference inclination, default 0 */
sprintf(mes, "Give Briggs reference inclination");
br_incl = 0;
def = 2;
nel = 1;
userdble_tir(startinfv -> arel, &br_incl, &nel, &def, "BR_INCL=", mes);
/* Ask for the angle range, 0: 10-360, 1:-180-180 */
sprintf(mes, "Give range for tiplon diagram 0: 10-360, 1:-180-180");
gr_tlr = 0;
def = 2;
nel = 1;
userint_tir(startinfv -> arel, &gr_tlr, &nel, &def, "GR_TLR=", mes);
/* Then get the stuff in radian */
br_incl = DEGTORAD*br_incl;
br_pa = DEGTORAD*br_pa;
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR)) {
for (j = 0; j < rpm -> nur; ++j) {
/* We get the radian position angle and the radian inclination */
nrefr[0] = DEGTORAD*rpm -> par[PINCL*rpm -> nur+j];
nrefr[1] = DEGTORAD*rpm -> par[PPA*rpm -> nur+j];
/* Then we do this: */
value = sin(br_incl)*sin(nrefr[0])*cos(nrefr[1]-br_pa)+cos(br_incl)*cos(nrefr[0]);
array[j] = value>1?0.0:RADTODEG*acos(value);
/**************/
/**************/
/* sprintf(obsmes, "tip: %.2f",array[j]); */
/* anyout_tir(&obsint, obsmes); */
/**************/
}
for (j = 0; j < rpm -> nr; ++j) {
/* We get the radian position angle and the radian inclination */
nrefr[0] = DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j];
nrefr[1] = DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j];
/* Then we do this: */
value = sin(br_incl)*sin(nrefr[0])*cos(nrefr[1]-br_pa)+cos(br_incl)*cos(nrefr[0]);
larray[j] = value>1?0.0:RADTODEG*acos(value);
}
}
else {
/* First scan for the first point where pa and incl are different */
rescval = 0.0;
for (j = 0; j < rpm -> nr; ++j) {
nrefr[0] = DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j];
nrefr[1] = DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j];
if (maths_checkeq(nrefr[0], br_incl, 1.0E-6) || maths_checkeq(nrefr[1], br_pa, FLOAT_ACCURACY)) {
x = sin(nrefr[0])*sin(nrefr[1]-br_pa);
y = -cos(br_incl)*sin(nrefr[0])*cos(nrefr[1]-br_pa)+sin(br_incl)*cos(nrefr[0]);
if (y == 0)
y = 1E-15;
rescval = (x/y);
if ((x<=0) && (y > 0))
rescval = -atan(rescval);
if ((x>=0) && (y > 0))
rescval = TWOPI-atan(rescval);
if ((x>=0) && (y < 0))
rescval = TWOPI/2-atan(rescval);
if ((x<=0) && (y < 0))
rescval = TWOPI/2-atan(rescval);
break;
}
}
/* Ask for the reference LON */
sprintf(mes, "Give value for indefinite LON");
gr_tll = RADTODEG*rescval;
def = 2;
nel = 1;
userdble_tir(startinfv -> arel, &gr_tll, &nel, &def, "GR_TLL=", mes);
rescval = DEGTORAD*gr_tll;
/* sprintf(obsmes, "graph: %.2f", gr_tll); */
/* anyout_tir(&obsint, obsmes); */
for (j = 0; j < rpm -> nr; ++j) {
/* We get the radian position angle and the radian inclination */
nrefr[0] = DEGTORAD*rpm -> modpar[PINCL*rpm -> nr+j];
nrefr[1] = DEGTORAD*rpm -> modpar[PPA*rpm -> nr+j];
/* Then we do this: */
if (maths_checkeq(nrefr[0], br_incl, 1.0E-6) || maths_checkeq(nrefr[1], br_pa, FLOAT_ACCURACY)) {
x = sin(nrefr[0])*sin(nrefr[1]-br_pa);
y = -cos(br_incl)*sin(nrefr[0])*cos(nrefr[1]-br_pa)+sin(br_incl)*cos(nrefr[0]);
if (y == 0.0)
y = 1E-15;
value = (x/y);
if ((x<=0) && (y > 0))
value = -atan(value);
if ((x>=0) && (y > 0))
value = TWOPI-atan(value);
if ((x>=0) && (y < 0))
value = TWOPI/2-atan(value);
if ((x<=0) && (y < 0))
value = TWOPI/2-atan(value);
else if ((x<=0) && (y == 0))
value = TWOPI/4;
else if ((x>=0) && (y == 0))
value = 3*TWOPI/4;
}
else
value = rescval;
larray[j] = RADTODEG*value;
if ((gr_tlr)) {
if ((larray[j] > 180))
larray[j] = larray[j]-360.0;
}
}
for (j = 0; j < rpm -> nur; ++j) {
/* We get the radian position angle and the radian inclination */
nrefr[0] = DEGTORAD*rpm -> par[PINCL*rpm -> nur+j];
nrefr[1] = DEGTORAD*rpm -> par[PPA*rpm -> nur+j];
/* Then we do this: */
if (maths_checkeq(nrefr[0], br_incl, 1.0E-6) || maths_checkeq(nrefr[1], br_pa, FLOAT_ACCURACY)) {
x = sin(nrefr[0])*sin(nrefr[1]-br_pa);
y = -cos(br_incl)*sin(nrefr[0])*cos(nrefr[1]-br_pa)+sin(br_incl)*cos(nrefr[0]);
value = (x/y);
/**************/
/**************/
/* sprintf(obsmes, "graph: x: %.2f y: %.2f", x,y); */
/* anyout_tir(&obsint, obsmes); */
/**************/
if ((x<=0) && (y > 0))
value = -atan(value);
else if ((x>=0) && (y > 0))
value = TWOPI-atan(value);
else if ((x>=0) && (y < 0))
value = TWOPI/2-atan(value);
else if ((x<=0) && (y < 0))
value = TWOPI/2-atan(value);
else if ((x<=0) && (y == 0))
value = TWOPI/4;
else if ((x>=0) && (y == 0))
value = 3*TWOPI/4;
}
else
value = rescval;
array[j] = RADTODEG*value;
if ((gr_tlr)) {
if ((array[j] > 180))
array[j] = array[j]-360.0;
}
/**************/
/**************/
/* sprintf(obsmes, "lon: %.2f",array[j]); */
/* anyout_tir(&obsint, obsmes); */
/**************/
}
}
}
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns a legend string suitable for the use in the pgp module */
static void gr_filllegend(int ident, char *string, int ndisks)
{
int disk;
if ((string)) {
if (ident == RADI) { sprintf(string, "R: Radius"); return;}
if (ident == VROT) { sprintf(string, "VROT: Rotation velocity" ); return;}
if (ident == VRAD) { sprintf(string, "VRAD: Radial velocity" ); return;}
if (ident == VVER) { sprintf(string, "VROT: Vertical velocity" ); return;}
if (ident == DVRO) { sprintf(string, "DVRO: Gradient of rotation velocity" ); return;}
if (ident == DVRA) { sprintf(string, "DVRA: Gradient of radial velocity" ); return;}
if (ident == DVVE) { sprintf(string, "VROT: Gradient of vertical velocity" ); return;}
if (ident == ZDRO) { sprintf(string, "ZDRO: Onset rotation change" ); return;}
if (ident == ZDRA) { sprintf(string, "ZDRA: Onset radial v change" ); return;}
if (ident == ZDVE) { sprintf(string, "ZDVE: Onset vertical v change" ); return;}
if (ident == Z0) { sprintf(string, "SCHT: Scaleheight" ); return;}
if (ident == SDIS) { sprintf(string, "DISP: Dispersion" ); return;}
if (ident == CLNR) { sprintf(string, "CLNR: Sub-Cloud number" ); return;}
if (ident == VM0A) { sprintf(string, "VM0A: Velocity harmonics, 0th order" ); return;}
if (ident == VM1A) { sprintf(string, "VM1A: Velocity harmonics, 1st order, amp" ); return;}
if (ident == VM1P) { sprintf(string, "VM1P: Velocity harmonics, 1st order, phase"); return;}
if (ident == VM2A) { sprintf(string, "VM2A: Velocity harmonics, 2nd order, amp" ); return;}
if (ident == VM2P) { sprintf(string, "VM2P: Velocity harmonics, 2nd order, phase"); return;}
if (ident == VM3A) { sprintf(string, "VM3A: Velocity harmonics, 3rd order, amp" ); return;}
if (ident == VM3P) { sprintf(string, "VM3P: Velocity harmonics, 3rd order, phase"); return;}
if (ident == VM4A) { sprintf(string, "VM4A: Velocity harmonics, 4th order, amp" ); return;}
if (ident == VM4P) { sprintf(string, "VM4P: Velocity harmonics, 4th order, phase"); return;}
if (ident == RA1A) { sprintf(string, "RA1A: Velocity harmonics (radial), 1st order, amp" ); return;}
if (ident == RA1P) { sprintf(string, "RA1P: Velocity harmonics (radial), 1st order, phase"); return;}
if (ident == RA2A) { sprintf(string, "RA2A: Velocity harmonics (radial), 2nd order, amp" ); return;}
if (ident == RA2P) { sprintf(string, "RA2P: Velocity harmonics (radial), 2nd order, phase"); return;}
if (ident == RA3A) { sprintf(string, "RA3A: Velocity harmonics (radial), 3rd order, amp" ); return;}
if (ident == RA3P) { sprintf(string, "RA3P: Velocity harmonics (radial), 3rd order, phase"); return;}
if (ident == RA4A) { sprintf(string, "RA4A: Velocity harmonics (radial), 4th order, amp" ); return;}
if (ident == RA4P) { sprintf(string, "RA4P: Velocity harmonics (radial), 4th order, phase"); return;}
if (ident == RO1A) { sprintf(string, "RO1A: Velocity harmonics (tangential), 1st order, amp" ); return;}
if (ident == RO1P) { sprintf(string, "RO1P: Velocity harmonics (tangential), 1st order, phase"); return;}
if (ident == RO2A) { sprintf(string, "RO2A: Velocity harmonics (tangential), 2nd order, amp" ); return;}
if (ident == RO2P) { sprintf(string, "RO2P: Velocity harmonics (tangential), 2nd order, phase"); return;}
if (ident == RO3A) { sprintf(string, "RO3A: Velocity harmonics (tangential), 3rd order, amp" ); return;}
if (ident == RO3P) { sprintf(string, "RO3P: Velocity harmonics (tangential), 3rd order, phase"); return;}
if (ident == RO4A) { sprintf(string, "RO4A: Velocity harmonics (tangential), 4th order, amp" ); return;}
if (ident == RO4P) { sprintf(string, "RO4P: Velocity harmonics (tangential), 4th order, phase"); return;}
if (ident == SBR) { sprintf(string, "SBR: Surface brightness" ); return;}
if (ident == SM1A) { sprintf(string, "SM1A: Sbr harmonics, 1st order, amp" ); return;}
if (ident == SM1P) { sprintf(string, "SM1P: Sbr harmonics, 1st order, phase" ); return;}
if (ident == SM2A) { sprintf(string, "SM2A: Sbr harmonics, 2nd order, amp" ); return;}
if (ident == SM2P) { sprintf(string, "SM2P: Sbr harmonics, 2nd order, phase" ); return;}
if (ident == SM3A) { sprintf(string, "SM3A: Sbr harmonics, 3rd order, amp" ); return;}
if (ident == SM3P) { sprintf(string, "SM3P: Sbr harmonics, 3rd order, phase" ); return;}
if (ident == SM4A) { sprintf(string, "SM4A: Sbr harmonics, 4th order, amp" ); return;}
if (ident == SM4P) { sprintf(string, "SM4P: Sbr harmonics, 4th order, phase" ); return;}
if (ident == GA1A) { sprintf(string, "GA1A: Sbr Gaussian 1, amplitude" ); return;}
if (ident == GA1P) { sprintf(string, "GA1P: Sbr Gaussian 1, , phase" ); return;}
if (ident == GA1D) { sprintf(string, "GA1D: Sbr Gaussian 1, dispersion" ); return;}
if (ident == GA2A) { sprintf(string, "GA2A: Sbr Gaussian 2, amplitude" ); return;}
if (ident == GA2P) { sprintf(string, "GA2P: Sbr Gaussian 2, , phase" ); return;}
if (ident == GA2D) { sprintf(string, "GA2D: Sbr Gaussian 2, dispersion" ); return;}
if (ident == GA3A) { sprintf(string, "GA3A: Sbr Gaussian 3, amplitude" ); return;}
if (ident == GA3P) { sprintf(string, "GA3P: Sbr Gaussian 3, , phase" ); return;}
if (ident == GA3D) { sprintf(string, "GA3D: Sbr Gaussian 3, dispersion" ); return;}
if (ident == GA4A) { sprintf(string, "GA4A: Sbr Gaussian 4, amplitude" ); return;}
if (ident == GA4P) { sprintf(string, "GA4P: Sbr Gaussian 4, , phase" ); return;}
if (ident == GA4D) { sprintf(string, "GA4D: Sbr Gaussian 4, dispersion" ); return;}
if (ident == AZ1P) { sprintf(string, "AZ1P: Model range 1, position" ); return;}
if (ident == AZ1W) { sprintf(string, "AZ1W: Model range 1, width" ); return;}
if (ident == AZ2P) { sprintf(string, "AZ2P: Model range 2, position" ); return;}
if (ident == AZ2W) { sprintf(string, "AZ2W: Model range 2, width" ); return;}
if (ident == INCL) { sprintf(string, "INCL: Inclination" ); return;}
if (ident == PA) { sprintf(string, "PA: Position angle" ); return;}
if (ident == XPOS) { sprintf(string, "RA: Right ascension of centre" ); return;}
if (ident == YPOS) { sprintf(string, "DEC: Declination of centre" ); return;}
if (ident == VSYS) { sprintf(string, "VSYS: Systemic velocity" ); return;}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR)) { sprintf(string, "WA: Warp angle" ); return;}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR)) {sprintf(string, "SD: Surface density" ); return;}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WOLD_GRAPHNR)) {sprintf(string, "WAOL: Warp angle, old definition" ); return;}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR)) {sprintf(string, "TIP: Tip angle" ); return;}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR)) {sprintf(string, "LON: LON angle" ); return;}
for (disk = 1; disk < ndisks; ++disk) {
if (ident == VROT+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VROT_%i Rotation velocity disk %i", disk+1, disk+1 ); return;}
if (ident == VRAD+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VRAD_%i Radial velocity disk %i", disk+1, disk+1 ); return;}
if (ident == VVER+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VROT_%i Vertical velocity disk %i", disk+1, disk+1 ); return;}
if (ident == DVRO+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DVRO_%i Gradient of rotation velocity disk %i", disk+1, disk+1 ); return;}
if (ident == DVRA+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DVRA_%i Gradient of radial velocity disk %i", disk+1, disk+1 ); return;}
if (ident == DVVE+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DVVE_%i Gradient of vertical velocity disk %i", disk+1, disk+1 ); return;}
if (ident == ZDRO+PRPARAMS+disk*NDPARAMS) { sprintf(string, "ZDRO_%i Onset rotation change disk %i", disk+1, disk+1 ); return;}
if (ident == ZDRA+PRPARAMS+disk*NDPARAMS) { sprintf(string, "ZDRA_%i Onset radial v change %i", disk+1, disk+1 ); return;}
if (ident == ZDVE+PRPARAMS+disk*NDPARAMS) { sprintf(string, "ZDVE_%i Onset vertical v change disk %i", disk+1, disk+1 ); return;}
if (ident == Z0 +PRPARAMS+disk*NDPARAMS) { sprintf(string, "SCHT_%i Scaleheight disk %i", disk+1, disk+1 ); return;}
if (ident == SDIS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "DISP_%i Dispersion disk %i", disk+1, disk+1 ); return;}
if (ident == CLNR+PRPARAMS+disk*NDPARAMS) { sprintf(string, "CLNR_%i Sub-Cloud number disk %i", disk+1, disk+1 ); return;}
if (ident == VM0A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM0A_%i Velocity harmonics, 0th order disk %i", disk+1, disk+1 ); return;}
if (ident == VM1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM1A_%i Velocity harmonics, 1st order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == VM1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM1P_%i Velocity harmonics, 1st order, phase disk %i", disk+1, disk+1); return;}
if (ident == VM2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM2A_%i Velocity harmonics, 2nd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == VM2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM2P_%i Velocity harmonics, 2nd order, phase disk %i", disk+1, disk+1); return;}
if (ident == VM3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM3A_%i Velocity harmonics, 3rd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == VM3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM3P_%i Velocity harmonics, 3rd order, phase disk %i", disk+1, disk+1); return;}
if (ident == VM4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM4A_%i Velocity harmonics, 4th order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == VM4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VM4P_%i Velocity harmonics, 4th order, phase disk %i", disk+1, disk+1); return;}
if (ident == RA1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA1A_%i Velocity harmonics (radial), 1st order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RA1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA1P_%i Velocity harmonics (radial), 1st order, phase disk %i", disk+1, disk+1); return;}
if (ident == RA2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA2A_%i Velocity harmonics (radial), 2nd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RA2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA2P_%i Velocity harmonics (radial), 2nd order, phase disk %i", disk+1, disk+1); return;}
if (ident == RA3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA3A_%i Velocity harmonics (radial), 3rd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RA3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA3P_%i Velocity harmonics (radial), 3rd order, phase disk %i", disk+1, disk+1); return;}
if (ident == RA4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA4A_%i Velocity harmonics (radial), 4th order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RA4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RA4P_%i Velocity harmonics (radial), 4th order, phase disk %i", disk+1, disk+1); return;}
if (ident == RO1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO1A_%i Velocity harmonics (tangential), 1st order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RO1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO1P_%i Velocity harmonics (tangential), 1st order, phase disk %i", disk+1, disk+1); return;}
if (ident == RO2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO2A_%i Velocity harmonics (tangential), 2nd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RO2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO2P_%i Velocity harmonics (tangential), 2nd order, phase disk %i", disk+1, disk+1); return;}
if (ident == RO3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO3A_%i Velocity harmonics (tangential), 3rd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RO3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO3P_%i Velocity harmonics (tangential), 3rd order, phase disk %i", disk+1, disk+1); return;}
if (ident == RO4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO4A_%i Velocity harmonics (tangential), 4th order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == RO4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "RO4P_%i Velocity harmonics (tangential), 4th order, phase disk %i", disk+1, disk+1); return;}
if (ident == SBR +PRPARAMS+disk*NDPARAMS) { sprintf(string, "SBR_%i Surface brightness disk %i", disk+1, disk+1 ); return;}
if (ident == SM1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM1A_%i Sbr harmonics, 1st order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == SM1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM1P_%i Sbr harmonics, 1st order, phase disk %i", disk+1, disk+1 ); return;}
if (ident == SM2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM2A_%i Sbr harmonics, 2nd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == SM2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM2P_%i Sbr harmonics, 2nd order, phase disk %i", disk+1, disk+1 ); return;}
if (ident == SM3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM3A_%i Sbr harmonics, 3rd order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == SM3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM3P_%i Sbr harmonics, 3rd order, phase disk %i", disk+1, disk+1 ); return;}
if (ident == SM4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM4A_%i Sbr harmonics, 4th order, amp disk %i", disk+1, disk+1 ); return;}
if (ident == SM4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "SM4P_%i Sbr harmonics, 4th order, phase disk %i", disk+1, disk+1 ); return;}
if (ident == GA1A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA1A_%i Sbr Gaussian 1, amplitude disk %i", disk+1, disk+1 ); return;}
if (ident == GA1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA1P_%i Sbr Gaussian 1, , phase disk %i", disk+1, disk+1 ); return;}
if (ident == GA1D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA1D_%i Sbr Gaussian 1, dispersion disk %i", disk+1, disk+1 ); return;}
if (ident == GA2A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA2A_%i Sbr Gaussian 2, amplitude disk %i", disk+1, disk+1 ); return;}
if (ident == GA2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA2P_%i Sbr Gaussian 2, , phase disk %i", disk+1, disk+1 ); return;}
if (ident == GA2D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA2D_%i Sbr Gaussian 2, dispersion disk %i", disk+1, disk+1 ); return;}
if (ident == GA3A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA3A_%i Sbr Gaussian 3, amplitude disk %i", disk+1, disk+1 ); return;}
if (ident == GA3P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA3P_%i Sbr Gaussian 3, , phase disk %i", disk+1, disk+1 ); return;}
if (ident == GA3D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA3D_%i Sbr Gaussian 3, dispersion disk %i", disk+1, disk+1 ); return;}
if (ident == GA4A+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA4A_%i Sbr Gaussian 4, amplitude disk %i", disk+1, disk+1 ); return;}
if (ident == GA4P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA4P_%i Sbr Gaussian 4, , phase disk %i", disk+1, disk+1 ); return;}
if (ident == GA4D+PRPARAMS+disk*NDPARAMS) { sprintf(string, "GA4D_%i Sbr Gaussian 4, dispersion disk %i", disk+1, disk+1 ); return;}
if (ident == AZ1P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ1P_%i Model range 1, position disk %i", disk+1, disk+1 ); return;}
if (ident == AZ1W+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ1W_%i Model range 1, width disk %i", disk+1, disk+1 ); return;}
if (ident == AZ2P+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ2P_%i Model range 2, position disk %i", disk+1, disk+1 ); return;}
if (ident == AZ2W+PRPARAMS+disk*NDPARAMS) { sprintf(string, "AZ2W_%i Model range 2, width disk %i", disk+1, disk+1 ); return;}
if (ident == INCL+PRPARAMS+disk*NDPARAMS) { sprintf(string, "INCL_%i Inclination disk %i", disk+1, disk+1 ); return;}
if (ident == PA +PRPARAMS+disk*NDPARAMS) { sprintf(string, "PA_%i Position angle disk %i", disk+1, disk+1 ); return;}
if (ident == XPOS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "XPOS_%i Right ascension of centre disk %i", disk+1, disk+1 ); return;}
if (ident == YPOS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "YPOS_%i Declination of centre disk %i", disk+1, disk+1 ); return;}
if (ident == VSYS+PRPARAMS+disk*NDPARAMS) { sprintf(string, "VSYS_%i Systemic velocity disk %i", disk+1, disk+1 ); return;}
}
string[0] = '\0'; return;
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Returns the scale for one unit to the alternative unit */
static void gr_fillscaling(loginf *log, hdrinf *hdr, int ident, float *scale, float *zero, int ndisks)
{
if (ident == RADI) {
*scale = 1000.0*log -> distance*TWOPI/(360*60*60);
*zero = 0.0;
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WA_GRAPHNR)) {
*scale = 1.0;
*zero = 0.0;
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+DENS_GRAPHNR)) {
*scale = UTOSOLAR;
*zero = 0.0;
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+WOLD_GRAPHNR)) {
*scale = 1.0;
*zero = 0.0;
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+TIP_GRAPHNR)) {
*scale = 1.0;
*zero = 0.0;
return;
}
if (ident == (NPARAMS+(ndisks-1)*NDPARAMS+LON_GRAPHNR)) {
*scale = 1.0;
*zero = 0.0;
return;
}
*scale = 1.0;
*zero = 0.0;
/* ident = ident%NDPARAMS?ident%NDPARAMS:NDPARAMS; */
ident = (ident-NSSDPARAMS-1)%NDPARAMS + NSSDPARAMS + 1;
switch (ident) {
case VROT:
*scale = 1.0;
*zero = 0.0;
return;
case VRAD:
*scale = 1.0;
*zero = 0.0;
return;
case VVER:
*scale = 1.0;
*zero = 0.0;
return;
case DVRO:
*scale = 1.0/(log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0);
*zero = 0.0;
return;
case DVRA:
*scale = 1.0/(log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0);
*zero = 0.0;
return;
case DVVE:
*scale = 1.0/(log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0);
*zero = 0.0;
return;
case ZDRO:
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case ZDRA:
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case ZDVE:
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case Z0:
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case SDIS:
*scale = 1.0;
*zero = 0.0;
return;
case CLNR:
*scale = 1.0;
*zero = 0.0;
return;
case VM0A: *scale = 1.0; *zero = 0.0; return;
case VM1A: *scale = 1.0; *zero = 0.0; return;
case VM1P: *scale = 1.0; *zero = 0.0; return;
case VM2A: *scale = 1.0; *zero = 0.0; return;
case VM2P: *scale = 1.0; *zero = 0.0; return;
case VM3A: *scale = 1.0; *zero = 0.0; return;
case VM3P: *scale = 1.0; *zero = 0.0; return;
case VM4A: *scale = 1.0; *zero = 0.0; return;
case VM4P: *scale = 1.0; *zero = 0.0; return;
case RA1A: *scale = 1.0; *zero = 0.0; return;
case RA1P: *scale = 1.0; *zero = 0.0; return;
case RA2A: *scale = 1.0; *zero = 0.0; return;
case RA2P: *scale = 1.0; *zero = 0.0; return;
case RA3A: *scale = 1.0; *zero = 0.0; return;
case RA3P: *scale = 1.0; *zero = 0.0; return;
case RA4A: *scale = 1.0; *zero = 0.0; return;
case RA4P: *scale = 1.0; *zero = 0.0; return;
case RO1A: *scale = 1.0; *zero = 0.0; return;
case RO1P: *scale = 1.0; *zero = 0.0; return;
case RO2A: *scale = 1.0; *zero = 0.0; return;
case RO2P: *scale = 1.0; *zero = 0.0; return;
case RO3A: *scale = 1.0; *zero = 0.0; return;
case RO3P: *scale = 1.0; *zero = 0.0; return;
case RO4A: *scale = 1.0; *zero = 0.0; return;
case RO4P: *scale = 1.0; *zero = 0.0; return;
case WM0A :
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case WM1A :
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case WM1P :
*scale = 1.0;
*zero = 0.0;
return;
case WM2A :
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case WM2P :
*scale = 1.0;
*zero = 0.0;
return;
case WM3A :
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case WM3P :
*scale = 1.0;
*zero = 0.0;
return;
case WM4A :
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case WM4P :
*scale = 1.0;
*zero = 0.0;
return;
case LS0 :
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case LC0 :
*scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0;
*zero = 0.0;
return;
case SBR:
*scale = hdr -> itou;
*zero = 0.0;
return;
case SM1A: *scale = hdr -> itou; *zero = 0.0; return;
case SM1P: *scale = 1.0; *zero = 0.0; return;
case SM2A: *scale = hdr -> itou; *zero = 0.0; return;
case SM2P: *scale = 1.0; *zero = 0.0; return;
case SM3A: *scale = hdr -> itou; *zero = 0.0; return;
case SM3P: *scale = 1.0; *zero = 0.0; return;
case SM4A: *scale = hdr -> itou; *zero = 0.0; return;
case SM4P: *scale = 1.0; *zero = 0.0; return;
case GA1A: *scale = hdr -> itou; *zero = 0.0; return;
case GA1P: *scale = 1.0; *zero = 0.0; return;
case GA1D: *scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0; *zero = 0.0; return;
case GA2A: *scale = hdr -> itou; *zero = 0.0; return;
case GA2P: *scale = 1.0; *zero = 0.0; return;
case GA2D: *scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0; *zero = 0.0; return;
case GA3A: *scale = hdr -> itou; *zero = 0.0; return;
case GA3P: *scale = 1.0; *zero = 0.0; return;
case GA3D: *scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0; *zero = 0.0; return;
case GA4A: *scale = hdr -> itou; *zero = 0.0; return;
case GA4P: *scale = 1.0; *zero = 0.0; return;
case GA4D: *scale = log -> distance*TWOPI/(360.0*60.0*60.0)*1000000.0; *zero = 0.0; return;
case AZ1P: *scale = 1.0; *zero = 0.0; return;
case AZ1W: *scale = 1.0; *zero = 0.0; return;
case AZ2P: *scale = 1.0; *zero = 0.0; return;
case AZ2W: *scale = 1.0; *zero = 0.0; return;
case INCL:
*scale = DEGTORAD;
*zero = 0.0;
return;
case PA:
*scale = DEGTORAD;
*zero = DEGTORAD*180.0;
return;
case XPOS:
*scale = 1000.0*log -> distance*TWOPI*cos(fabs(log -> yref)*TWOPI/360.0)/360.0;
*zero = 1000.0*(-log -> xref)*log -> distance*TWOPI*cos(fabs(log -> yref)*TWOPI/360.0)/360.0;
return;
case YPOS:
*scale = 1000.0*log -> distance*TWOPI/360.0;
*zero = 1000.0*(-log -> yref)*log -> distance*TWOPI/360.0;
return;
case VSYS:
*scale = 1.0;
*zero = 0.0;
return;
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Produces a renzogram with the rings */
static int renzo(startinf *startinfv, loginf *log, hdrinf *hdr, ringparms *rpm)
{
int i,j,k;
char *renzoname = NULL;
char mes[81];
int def;
int nel;
qfits_header *header = NULL;
Cube thecube;
int refine;
double majhax;
double minhax;
double point[3];
int keypres, nread, nreturned;
char **varystr = NULL;
/* First check if the user wants a renzogram output */
/* sprintf(mes, "Give inclinogram name:"); */
/* for (i = 0; i < 200; ++i) */
/* renzoname[i] = ' '; */
/* renzoname[200] = '\0'; */
/* def = 2; */
/* nel = 1; */
/* userchar_tir(renzoname, &nel, &def, "INCLINO=", mes); */
/* termsinglestr(renzoname); */
/* The default is to do nothing */
/* cancel_tir(startinfv -> arel, "INCLINO"); */
if (simparse_scn_arel_readval_stringlist(startinfv -> arel, "INCLINO", "Give graphics (pgplot) device.", 0, NULL, 0, -1, 0, 0, &keypres, &nread, &nreturned, &varystr))
goto error;
if ((varystr[0])) {
if (!(renzoname = simparse_copystring(varystr[0]))) {
goto error;
}
}
else {
if (!(renzoname = simparse_copystring(""))) {
goto error;
}
}
freeparsed(varystr);
varystr = NULL;
if (*renzoname == '\0') {
free(renzoname);
return 1;
}
/* Ask for refinement */
sprintf(mes, "Give inclinogram refinement:");
def = 2;
nel = 1;
while (refine <= 0) {
refine = 1;
userint_tir(startinfv -> arel, &refine, &nel, &def, "IN_REFINE=", mes);
if (refine <= 0) {
cancel_tir(startinfv -> arel, "IN_REFINE=", 2);
sprintf(mes, "IN_REFINE= must be greater than 0");
def = 1;
}
}
if (!(header = makerenzohdr(hdr, rpm -> nur, refine)))
return 1;
/* Now arrange the cube */
thecube.refpix_x = 0;
thecube.refpix_y = 0;
thecube.refpix_v = 0;
thecube.size_x = hdr -> bsize1*refine;
thecube.size_y = hdr -> bsize2*refine;
thecube.size_v = rpm -> nur;
thecube.scale = 1.0;
thecube.padding = 0;
thecube.points = NULL;
/* Allocate the cube */
if (!(thecube.points = (float *) malloc(thecube.size_x*thecube.size_y*thecube.size_v*sizeof(float))))
goto error;
/* Now get the best-fit values and turn them into internal units */
/* We read all values into the par array */
tir_get_grid(log, rpm, log -> outarray);
for (j = 0; j < rpm -> nur*(NPARAMS+(rpm -> ndisks-1)*NDPARAMS)+NSPARAMS; ++j)
rpm -> par[j] = log -> outarray[j];
/* We convert to internal units and interpolate over */
changetointern(rpm -> par, rpm -> nur, hdr, rpm -> ndisks);
/* Now se go through the planes, and hence the rings */
for (i = 0; i < thecube.size_v; ++i) {
/* First calculate the major and the minor half axis */
majhax = rpm -> par[PRADI*rpm -> nur+i]*refine;
minhax = fabs(cos(rpm -> par[PINCL*rpm -> nur+i]))*majhax;
/* Each point in the plane will be put to the origin, then be rotated back */
for (j = 0; j < thecube.size_x; ++j) {
for (k = 0; k < thecube.size_y; ++k) {
point[0] = cos(rpm -> par[PPA*rpm -> nur+i])*(((double) j) - ((rpm -> par[PXPOS*rpm -> nur+i]+0.5)*refine-0.5))+sin(rpm -> par[PPA*rpm -> nur+i])*(((double) k) - ((rpm -> par[PYPOS*rpm -> nur+i]+0.5)*refine-0.5));
point[1] = -sin(rpm -> par[PPA*rpm -> nur+i])*(((double) j) - ((rpm -> par[PXPOS*rpm -> nur+i]+0.5)*refine-0.5))+cos(rpm -> par[PPA*rpm -> nur+i])*(((double) k) - ((rpm -> par[PYPOS*rpm -> nur+i]+0.5)*refine-0.5));
if ((minhax > 0.5)) {
/* Now check if the position is inside an ellipse, if yes, the point is 1, if not 0 */
if (((minhax*point[0])*(minhax*point[0])+(majhax*point[1])*(majhax*point[1])) > (minhax*minhax*majhax*majhax))
thecube.points[j+thecube.size_x*(k+thecube.size_y*i)] = 0;
else
thecube.points[j+thecube.size_x*(k+thecube.size_y*i)] = 1;
}
else {
/* We want to prevent that nothing is drawn, so we plot a line if minhax is 0 */
if (!maths_checkinbetw(1,-1,point[1]) && (point[0]*point[0] <= majhax*majhax))
thecube.points[j+thecube.size_x*(k+thecube.size_y*i)] = 1;
else
thecube.points[j+thecube.size_x*(k+thecube.size_y*i)] = 0;
}
}
}
/* If the major axis is 0, we draw a point */
if (majhax < 1)
thecube.points[roundnormal((rpm -> par[PXPOS*rpm -> nur+i]+0.5)*refine-0.5)+thecube.size_x*(roundnormal((rpm -> par[PYPOS*rpm -> nur+i]+0.5)*refine-0.5)+thecube.size_y*i)] = 1;
}
/* Output it */
ftsout_writecube(renzoname, &thecube, header);
/* Deallocate everything */
ftsout_header_destroy(header);
free(thecube.points);
/* Return, deeply satisfied */
if ((renzoname))
free(renzoname);
if (varystr)
freeparsed(varystr);
return 0;
error:
if ((header))
ftsout_header_destroy(header);
if ((thecube.points))
free((thecube.points));
if ((renzoname))
free(renzoname);
if (varystr)
freeparsed(varystr);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Make a qfits header suitable for coolgal output */
static qfits_header *makerenzohdr(hdrinf *hdr, int planes, int refine)
{
/* char key[9] */
char value[21];
/* int j; */
/* int level = 0; */
/* int err = 0; */
qfits_header *header = NULL;
/* The bitpix is -32 */
if (!(header = ftsout_putcard(header, "BITPIX","-32")))
goto error;
/* The number of axes is set to three */
if (!ftsout_putcard(header, "NAXIS","3"))
goto error;
/* Now get the axis numbers */
sprintf(value, "%i", hdr -> bsize1*refine);
if (!ftsout_putcard(header, "NAXIS1",value))
goto error;
sprintf(value, "%i", hdr -> bsize2*refine);
if (!ftsout_putcard(header, "NAXIS2",value))
goto error;
/* The third axis is simply the number of planes */
sprintf(value, "%i", planes );
if (!ftsout_putcard(header, "NAXIS3",value))
goto error;
/* May contain an extension */
if (!ftsout_putcard(header, "EXTEND","T"))
goto error;
/* These are clear */
if (!ftsout_putcard(header, "BSCALE","1"))
goto error;
if (!ftsout_putcard(header, "BZERO","0"))
goto error;
/* The bunit is nothing */
if (!ftsout_putcard(header, "BUNIT","' '"))
goto error;
/* The cdelt is taken from the hdr struct, this should be ok with the unit being DEGREE*/
sprintf(value, "%.12E", hdr -> userglobcdelt[0]/refine);
if (!ftsout_putcard(header, "CDELT1", value))
goto error;
/* The crpix is copied from the header of the inset */
sprintf(value, "%.12E", (hdr -> setcrpix[0]-0.5)*refine+0.5);
if (!ftsout_putcard(header, "CRPIX1", value))
goto error;
/* The crval in user units -> degree */
sprintf(value, "%.12E", hdr -> userglobcrval[0]);
if (!ftsout_putcard(header, "CRVAL1", value))
goto error;
/* This is nasty, because we have to re-read the info */
/* sprintf(key, "CTYPE%i", hdr -> inaxperm[0]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* gdsd_rchar_tir(hdr -> inset, key, &(level), value, &err); */
if (!ftsout_putcard(header, "CTYPE1", hdr -> oric -> type_x))
goto error;
if (!ftsout_putcard(header, "CUNIT1", "'DEGREE '"))
goto error;
/* The cdelt is taken from the hdr struct, this should be ok with the unit being DEGREE*/
sprintf(value, "%.12E", hdr -> userglobcdelt[1]/refine);
if (!ftsout_putcard(header, "CDELT2", value))
goto error;
/* The crpix is copied from the header of the inset */
sprintf(value, "%.12E", (hdr -> setcrpix[1]-0.5)*refine+0.5);
if (!ftsout_putcard(header, "CRPIX2", value))
goto error;
/* The crval in user units -> degree */
sprintf(value, "%.12E", hdr -> userglobcrval[1]);
if (!ftsout_putcard(header, "CRVAL2", value))
goto error;
/* This is nasty, because we have to re-read the info */
/* sprintf(key, "CTYPE%i", hdr -> inaxperm[1]); */
/* for (j = 0; j < 20; ++j) */
/* value[j] = ' '; */
/* value[20] = '\0'; */
/* gdsd_rchar_tir(hdr -> inset, key, &(level), value, &err); */
if (!ftsout_putcard(header, "CTYPE2", hdr -> oric -> type_y))
goto error;
if (!ftsout_putcard(header, "CUNIT2", "'DEGREE '"))
goto error;
/* The third axis is the artificial one */
/* The cdelt is 1 */
sprintf(value, "%.12E", 1.0);
if (!ftsout_putcard(header, "CDELT3", value))
goto error;
/* crpix is at the start */
sprintf(value, "%.12E", 1.0);
if (!ftsout_putcard(header, "CRPIX3", value))
goto error;
/* This is exactly 0 */
if (!ftsout_putcard(header, "CRVAL3", "1.0"))
goto error;
/* The type is somthing without projection, this should do */
if (!ftsout_putcard(header, "CTYPE3", "' '"))
goto error;
/* This is nothing again */
if (!ftsout_putcard(header, "CUNIT3", "' '"))
goto error;
return header;
error:
if ((header))
ftsout_header_destroy(header);
header = NULL;
return header;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* deallocates an inf_sdis struct */
static int destroy_inf_sdis(inf_sdis *int_sdisv)
{
if (!(int_sdisv))
return 0;
/* if ((int_sdisv -> randstr)) */
/* free(int_sdisv -> randstr); */
free(int_sdisv);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* allocates an inf_sdis struct */
static inf_sdis *create_inf_sdis(void)
{
inf_sdis *create_inf_sdis = NULL;
if (!(create_inf_sdis = (inf_sdis *) malloc(sizeof(inf_sdis))))
return create_inf_sdis;
/* create_inf_sdis -> randstr = NULL; */
return create_inf_sdis;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* allocates an inf_smi struct */
static inf_smi *create_inf_smi(void)
{
inf_smi *create_inf_smi = NULL;
if (!(create_inf_smi = (inf_smi *) malloc(sizeof(inf_smi))))
return create_inf_smi;
/* create_inf_smi -> randstr = NULL; */
return create_inf_smi;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* deallocates an inf_sdis struct */
static int destroy_inf_smi(inf_smi *inf_smiv)
{
if (!(inf_smiv))
return 0;
/* if ((inf_smiv -> randstr)) */
/* free(inf_smiv -> randstr); */
free(inf_smiv);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm1 struct */
static int chkb_smi(ringparms *rpm, fitparms *fit)
{
int actiflag, disk, srnr;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_smiv[disk]))
if (!(rpm -> inf_smiv[disk] = create_inf_smi()))
return 1;
actiflag = 0;
/* check out subring calculation and calculation of surface density */
/* Zeroth order */
/* First order */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM1A))) {
rpm -> inf_smiv[disk] -> prs1 = rpm -> inf_smiv[disk] -> prc1 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs1 = rpm -> inf_smiv[disk] -> srprc1 = &srpr_smi_pas;
}
else {
actiflag = 1;
rpm -> inf_smiv[disk] -> prs1 = &pr_sm1s_act;
rpm -> inf_smiv[disk] -> prc1 = &pr_sm1c_act;
rpm -> inf_smiv[disk] -> srprs1 = &srpr_sm1s_act;
rpm -> inf_smiv[disk] -> srprc1 = &srpr_sm1c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM1P))) {
rpm -> inf_smiv[disk] -> prs1 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs1 = &srpr_smi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM1P, PIHALF))) {
rpm -> inf_smiv[disk] -> prc1 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprc1 = &srpr_smi_pas;
}
}
/* second order */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM2A))) {
rpm -> inf_smiv[disk] -> prs2 = rpm -> inf_smiv[disk] -> prc2 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs2 = rpm -> inf_smiv[disk] -> srprc2 = &srpr_smi_pas;
}
else {
actiflag = 1;
rpm -> inf_smiv[disk] -> prs2 = &pr_sm2s_act;
rpm -> inf_smiv[disk] -> prc2 = &pr_sm2c_act;
rpm -> inf_smiv[disk] -> srprs2 = &srpr_sm2s_act;
rpm -> inf_smiv[disk] -> srprc2 = &srpr_sm2c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM2P))) {
rpm -> inf_smiv[disk] -> prs2 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs2 = &srpr_smi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM2P, PIHALF))) {
rpm -> inf_smiv[disk] -> prs2 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs2 = &srpr_smi_pas;
}
}
/* third order */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM3A))) {
rpm -> inf_smiv[disk] -> prs3 = rpm -> inf_smiv[disk] -> prc3 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs3 = rpm -> inf_smiv[disk] -> srprc3 = &srpr_smi_pas;
}
else {
actiflag = 1;
rpm -> inf_smiv[disk] -> prs3 = &pr_sm3s_act;
rpm -> inf_smiv[disk] -> prc3 = &pr_sm3c_act;
rpm -> inf_smiv[disk] -> srprs3 = &srpr_sm3s_act;
rpm -> inf_smiv[disk] -> srprc3 = &srpr_sm3c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM3P))) {
rpm -> inf_smiv[disk] -> prs3 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs3 = &srpr_smi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM3P, PIHALF))) {
rpm -> inf_smiv[disk] -> prc3 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprc3 = &srpr_smi_pas;
}
}
/* fourth order */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM4A))) {
rpm -> inf_smiv[disk] -> prs4 = rpm -> inf_smiv[disk] -> prc4 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs4 = rpm -> inf_smiv[disk] -> srprc4 = &srpr_smi_pas;
}
else {
actiflag = 1;
rpm -> inf_smiv[disk] -> prs4 = &pr_sm4s_act;
rpm -> inf_smiv[disk] -> prc4 = &pr_sm4c_act;
rpm -> inf_smiv[disk] -> srprs4 = &srpr_sm4s_act;
rpm -> inf_smiv[disk] -> srprc4 = &srpr_sm4c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM4P))) {
rpm -> inf_smiv[disk] -> prs4 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs4 = &srpr_smi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PSM4P, PIHALF))) {
rpm -> inf_smiv[disk] -> prs4 = &pr_smi_pas;
rpm -> inf_smiv[disk] -> srprs4 = &srpr_smi_pas;
}
}
/* we allocate the rng, since we will need it */
if ((actiflag)) {
for (srnr = 0; srnr < rpm -> nr; ++srnr)
if (!(rpm -> sd[disk][srnr].randstr))
if (!(rpm -> sd[disk][srnr].randstr = (maths_rstrf *) malloc(sizeof(maths_rstrf))))
goto error;
rpm -> inf_smiv[disk] -> prb0 = &pr_sm0b_act;
rpm -> inf_smiv[disk] -> srprb0 = &srpr_sm0b_act;
rpm -> inf_smiv[disk] -> srprsbrmax = &smi_sbrmax_act;
rpm -> inf_smiv[disk] -> getaz = &smi_getaz_harm;
rpm -> inf_smiv[disk] -> getcloudnumber = &smi_getcloudnumber_harm;
rpm -> inf_smiv[disk] -> rndmf_init = &rndmf_init_smi_act;
}
else {
rpm -> inf_smiv[disk] -> prb0 = &pr_sm0b_pas;
rpm -> inf_smiv[disk] -> srprsbrmax = &smi_sbrmax_pas;
rpm -> inf_smiv[disk] -> srprb0 = &srpr_smi_pas;
rpm -> inf_smiv[disk] -> getaz = &smi_getaz_cons;
rpm -> inf_smiv[disk] -> getcloudnumber = &smi_getcloudnumber_norm;
rpm -> inf_smiv[disk] -> rndmf_init = &rndmf_init_smi_pas;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_smi(rpm -> inf_smiv[disk]);
rpm -> inf_smiv[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function */
static void srpr_smi_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm0b_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].spb0 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*prm -> nr+srnr]*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm1s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].sps1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1A)*prm -> nr+srnr]*sinf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm1c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].spc1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1A)*prm -> nr+srnr]*cosf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm2s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].sps2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2A)*prm -> nr+srnr]*sinf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm2c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].spc2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2A)*prm -> nr+srnr]*cosf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm3s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].sps3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3A)*prm -> nr+srnr]*sinf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm3c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].spc3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3A)*prm -> nr+srnr]*cosf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm4s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].sps4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4A)*prm -> nr+srnr]*sinf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void srpr_sm4c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].spc4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4A)*prm -> nr+srnr]*cosf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4P)*prm -> nr+srnr])*prm -> sd[disk][srnr].sbrmax;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void smi_getcloudnumber_harm(void *rpm, int srnr, int disk)
{
ringparms *prm;
float nor;
float ringflux;
prm = (ringparms *) rpm;
/* Normalise to point source number instead of surface brightness */
if (fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*prm -> nr+srnr])-(fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1A)*prm -> nr+srnr])+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2A)*prm -> nr+srnr])+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3A)*prm -> nr+srnr])+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4A)*prm -> nr+srnr])) >= 0.0) {
ringflux = TWOPI*prm -> modpar[PRADI*prm -> nr+srnr]*prm -> radsep*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*prm -> nr+srnr];
/* This is the integral if there is no negative flux (because the integral of a harmonic function with order > 0 is 0), Kamphuis bugfix */
/* prm -> sd[disk][srnr].nharmnorm = (long) (ringflux/prm -> cflux[0]); -> */
prm -> sd[disk][srnr].nharmnorm = (long) (ringflux/prm -> cflux[disk]);
/* correct the point source flux */
if ((prm -> sd[disk][srnr].nharmnorm))
prm -> sd[disk][srnr].pf = fabs(ringflux)/prm -> sd[disk][srnr].nharmnorm;
else
/* Kamphuis bugfix */
/* prm -> sd[disk][srnr].pf = prm -> cflux[0]; */
prm -> sd[disk][srnr].pf = prm -> cflux[disk];
/* We allow for a negative pointsource flux, even if it makes no sense */
if (prm -> sd[disk][srnr].nharmnorm < 0) {
prm -> sd[disk][srnr].nharmnorm = -prm -> sd[disk][srnr].nharmnorm;
}
/* We determine the gridder to be the "normal" one */
prm -> sd[disk][srnr].gridpoint = &gridpoint_norm;
prm -> sd[disk][srnr].srput = &srput_norm;
}
else {
/* Normalise to point source number instead of surface brightness */
/* Kamphuis bugfix */
/* nor = prm -> modpar[PRADI*prm -> nr+srnr]*prm -> radsep/prm -> cflux[0]; -> */
nor = prm -> modpar[PRADI*prm -> nr+srnr]*prm -> radsep/prm -> cflux[disk];
/* Negative flux occurs, which is why we have to calculate the full integral (numerically) */
prm -> sd[disk][srnr].nharmnorm =
(long) maths_intabsfou4(
nor*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*prm -> nr+srnr],
nor*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1A)*prm -> nr+srnr],
prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1P)*prm -> nr+srnr],
nor*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2A)*prm -> nr+srnr],
prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2P)*prm -> nr+srnr],
nor*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3A)*prm -> nr+srnr],
prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3P)*prm -> nr+srnr],
nor*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4A)*prm -> nr+srnr],
prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4P)*prm -> nr+srnr]
);
/* We determine the gridder to be the "mixed" one */
prm -> sd[disk][srnr].gridpoint = &gridpoint_mixed;
prm -> sd[disk][srnr].srput = &srput_mixed;
/* We reset the number of positive and negative point sources */
}
/* Change the number of point sources */
prm -> sd[disk][srnr].n += prm -> sd[disk][srnr].nharmnorm;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void smi_getcloudnumber_norm(void *rpm, int srnr, int disk)
{
ringparms *prm;
float ringflux;
prm = (ringparms *) rpm;
ringflux = TWOPI*prm -> modpar[PRADI*prm -> nr+srnr]*prm -> radsep*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*prm -> nr+srnr];
/* This is the integral if there is no negative flux (because the integral of a harmonic function with order > 0 is 0) */
/* Kamphuis bugfix */
/* prm -> sd[disk][srnr].nharmnorm = (long) (ringflux/prm -> cflux[0]); -> */
prm -> sd[disk][srnr].nharmnorm = (long) (ringflux/prm -> cflux[disk]);
/* correct the point source flux */
if ((prm -> sd[disk][srnr].nharmnorm))
prm -> sd[disk][srnr].pf = fabs(ringflux)/prm -> sd[disk][srnr].nharmnorm;
else
/* Kamphuis bugfix */
/* prm -> sd[disk][srnr].pf = prm -> cflux[0]; -> */
prm -> sd[disk][srnr].pf = prm -> cflux[disk];
/* We allow for a negative pointsource flux, even if it makes no sense */
if (prm -> sd[disk][srnr].nharmnorm < 0) {
prm -> sd[disk][srnr].nharmnorm = -prm -> sd[disk][srnr].nharmnorm;
}
prm -> sd[disk][srnr].n += prm -> sd[disk][srnr].nharmnorm;
prm -> sd[disk][srnr].gridpoint = &gridpoint_norm;
prm -> sd[disk][srnr].srput = &srput_norm;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_smis/c_act */
static void pr_smi_pas(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm0b_pas(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
*sbr = 0.0;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm0b_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = prm -> sd[disk][srnr].spb0;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm1s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+sinaz*prm -> sd[disk][srnr].sps1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm2s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+(2.0*sinaz*cosaz)* prm -> sd[disk][srnr].sps2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm3s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+(3.0*sinaz-4.0*sinaz*sinaz*sinaz)*prm -> sd[disk][srnr].sps3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm4s_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+(8.0*sinaz*cosaz*cosaz*cosaz-4.0*sinaz*cosaz)* prm -> sd[disk][srnr].sps4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm1c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+cosaz* prm -> sd[disk][srnr].spc1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm2c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+(1.0-2.0*sinaz*sinaz)*prm -> sd[disk][srnr].spc2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm3c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+(4.0*cosaz*cosaz*cosaz-3.0*cosaz)*prm -> sd[disk][srnr].spc3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void pr_sm4c_act(void *rpm, float *sbr, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*sbr = *sbr+(8.0*cosaz*cosaz*cosaz*cosaz-8.0*cosaz*cosaz+1.0)*prm -> sd[disk][srnr].spc4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void smi_getaz_cons(void *rpm, float *az, float *sinaz, float *cosaz, int *signum, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*az = TWOPI*maths_rndmf(prm -> sd[disk][srnr].permrandstr);
*cosaz = cosf(*az);
*sinaz = sinf(*az);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void smi_getaz_harm(void *rpm, float *az, float *sinaz, float *cosaz, int *signum, int srnr, int disk)
{
ringparms *prm;
float sbr;
prm = (ringparms *) rpm;
while (1) {
*az = TWOPI*maths_rndmf(prm -> sd[disk][srnr].permrandstr);
*cosaz = cosf(*az);
*sinaz = sinf(*az);
/* Caution!!! This function replaces sbr with the constant value */
(*(prm -> inf_smiv[disk] -> prb0))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
/* Caution!!! The following functions add to sbr */
(*(prm -> inf_smiv[disk] -> prs1))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
(*(prm -> inf_smiv[disk] -> prs2))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
(*(prm -> inf_smiv[disk] -> prs3))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
(*(prm -> inf_smiv[disk] -> prs4))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
(*(prm -> inf_smiv[disk] -> prc1))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
(*(prm -> inf_smiv[disk] -> prc2))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
(*(prm -> inf_smiv[disk] -> prc3))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
(*(prm -> inf_smiv[disk] -> prc4))(rpm, &sbr, srnr, *sinaz, *cosaz, disk);
if (maths_rndmf(prm -> sd[disk][srnr].randstr) <= fabs(sbr))
break;
else {
/* This is to keep the pointsource lists similar */
maths_rndmf(prm -> sd[disk][srnr].permrandstr);
/* zprof(prm -> ltype[0], prm -> sd[disk][srnr].permrandstr)*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PZ0)*prm -> nr+srnr]; */
zprof(prm -> ltype[disk], prm -> sd[disk][srnr].permrandstr, &(prm -> sd[disk][srnr].y2));
(*(prm -> inf_sdisv[disk] -> pr_empty))(rpm, srnr, disk);
}
}
if (sbr >= 0)
*signum = 1;
else
*signum = 0;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates the sum of absolute amplitudes of surface brightness modes and puts that number in the sbrmax variable of the subring structure */
static void smi_sbrmax_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
double sbrmax;
prm = (ringparms *) rpm;
sbrmax = (fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSBR)*prm -> nr+srnr])+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM1A)*prm -> nr+srnr])+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM2A)*prm -> nr+srnr])+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM3A)*prm -> nr+srnr])+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSM4A)*prm -> nr+srnr]));
if (sbrmax != 0.0)
prm -> sd[disk][srnr].sbrmax = 1.0/sbrmax;
else
sbrmax = 2.0;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial surface brightness component and adds it to the input */
static void smi_sbrmax_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm1 struct */
static int chkb_gau(ringparms *rpm, fitparms *fit)
{
int actiflag, disk, srnr;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_gauv[disk]))
if (!(rpm -> inf_gauv[disk] = create_inf_gau()))
return 1;
actiflag = 0;
/* check out subring calculation and calculation of surface density */
/* First order */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PGA1A))) {
rpm -> inf_gauv[disk] -> srpr0 = &srpr_gau_pas;
rpm -> inf_gauv[disk] -> rndmf_init0 = &rndmf_init_gau_pas;
rpm -> inf_gauv[disk] -> getcloudnumber0 = gau_getcloudnumber_pas;
}
else {
rpm -> inf_gauv[disk] -> srpr0 = &srpr_gau_act;
rpm -> inf_gauv[disk] -> rndmf_init0 = &rndmf_init_gau_act;
rpm -> inf_gauv[disk] -> getcloudnumber0 = gau_getcloudnumber_act;
for (srnr = 0; srnr < rpm -> nr; ++srnr) {
if (!(rpm -> sd[disk][srnr].grandstr[0]))
if (!(rpm -> sd[disk][srnr].grandstr[0] = (maths_rstrf *) malloc(sizeof(maths_rstrf))))
goto error;
}
actiflag = 1;
}
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PGA2A))) {
rpm -> inf_gauv[disk] -> srpr1 = &srpr_gau_pas;
rpm -> inf_gauv[disk] -> rndmf_init1 = &rndmf_init_gau_pas;
rpm -> inf_gauv[disk] -> getcloudnumber1 = gau_getcloudnumber_pas;
}
else {
rpm -> inf_gauv[disk] -> srpr1 = &srpr_gau_act;
rpm -> inf_gauv[disk] -> rndmf_init1 = &rndmf_init_gau_act;
rpm -> inf_gauv[disk] -> getcloudnumber1 = gau_getcloudnumber_act;
for (srnr = 0; srnr < rpm -> nr; ++srnr) {
if (!(rpm -> sd[disk][srnr].grandstr[1]))
if (!(rpm -> sd[disk][srnr].grandstr[1] = (maths_rstrf *) malloc(sizeof(maths_rstrf))))
goto error;
}
actiflag = 1;
}
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PGA3A))) {
rpm -> inf_gauv[disk] -> srpr2 = &srpr_gau_pas;
rpm -> inf_gauv[disk] -> rndmf_init2 = &rndmf_init_gau_pas;
rpm -> inf_gauv[disk] -> getcloudnumber2 = gau_getcloudnumber_pas;
}
else {
rpm -> inf_gauv[disk] -> srpr2 = &srpr_gau_act;
rpm -> inf_gauv[disk] -> rndmf_init2 = &rndmf_init_gau_act;
rpm -> inf_gauv[disk] -> getcloudnumber2 = gau_getcloudnumber_act;
for (srnr = 0; srnr < rpm -> nr; ++srnr) {
if (!(rpm -> sd[disk][srnr].grandstr[2]))
if (!(rpm -> sd[disk][srnr].grandstr[2] = (maths_rstrf *) malloc(sizeof(maths_rstrf))))
goto error;
}
actiflag = 1;
}
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PGA4A))) {
rpm -> inf_gauv[disk] -> srpr3 = &srpr_gau_pas;
rpm -> inf_gauv[disk] -> rndmf_init3 = &rndmf_init_gau_pas;
rpm -> inf_gauv[disk] -> getcloudnumber3 = gau_getcloudnumber_pas;
}
else {
rpm -> inf_gauv[disk] -> srpr3 = &srpr_gau_act;
rpm -> inf_gauv[disk] -> rndmf_init3 = &rndmf_init_gau_act;
rpm -> inf_gauv[disk] -> getcloudnumber3 = gau_getcloudnumber_act;
for (srnr = 0; srnr < rpm -> nr; ++srnr) {
if (!(rpm -> sd[disk][srnr].grandstr[3]))
if (!(rpm -> sd[disk][srnr].grandstr[3] = (maths_rstrf *) malloc(sizeof(maths_rstrf))))
goto error;
}
actiflag = 1;
}
if ((actiflag)) {
;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_gau(rpm -> inf_gauv[disk]);
rpm -> inf_gauv[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* allocates an inf_gau struct */
static inf_gau *create_inf_gau(void)
{
inf_gau *create_inf_gau = NULL;
if (!(create_inf_gau = (inf_gau *) malloc(sizeof(inf_gau))))
return create_inf_gau;
/* for (i = 0; i < 4; ++i) */
/* create_inf_gau -> randstr[i] = NULL; */
return create_inf_gau;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* deallocates an inf_gau struct */
static int destroy_inf_gau(inf_gau *inf_gauv)
{
if (!(inf_gauv))
return 0;
/* for (i = 0; i < 4; ++i) { */
/* if ((inf_gauv -> randstr[i])) */
/* free(inf_gauv -> randstr[i]); */
/* } */
free(inf_gauv);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates Gaussian surface brightness dispersion in rad and adds it to the subring */
static void srpr_gau_act(void *rpm, int srnr, int number, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].gaudi[number] = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PGA1D+3*number)*prm -> nr+srnr]/prm -> modpar[PRADI*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void srpr_gau_pas(void *rpm, int srnr, int number, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Initialises the rng internal to the calulation of sdis */
static void rndmf_init_gau_act(void *rpm, int srnr, int n, int disk)
{
ringparms *prm;
int iseed[2];
prm = (ringparms *) rpm;
iseed[0] = prm -> iseed2+2+n;
iseed[1] = srnr;
/* Reset things */
maths_rndmf_init(iseed, prm -> sd[disk][srnr].grandstr[n]);
zprof(6, prm -> sd[disk][srnr].grandstr[n], &(prm -> sd[disk][srnr].y2));
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function doing nothing instead of rndmf_init_sdis_act */
static void rndmf_init_gau_pas(void *rpm, int srnr, int n, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void gau_getcloudnumber_act(void *rpm, int srnr, int group, int disk)
{
ringparms *prm;
float ringflux;
prm = (ringparms *) rpm;
/* This defines the amplitude as a real peak value in total surface brightness */
ringflux = SQRTOFTWOPI*prm -> modpar[PRADI*prm -> nr+srnr]*prm -> radsep*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PGA1A+3*group)*prm -> nr+srnr]*prm -> sd[disk][srnr].gaudi[group];
/* This defines the amplitude as the surface brightness averaged over a complete ring */
/* ringflux = TWOPI*prm -> modpar[PRADI*prm -> nr+srnr]*prm -> radsep*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PGA1A+3*group)*prm -> nr+srnr]; */
/* This is the integral if there is no negative flux (because the integral of a harmonic function with order > 0 is 0) */
prm -> sd[disk][srnr].ngaussian[group] = (long) fabs(ringflux/prm -> sd[disk][srnr].pf);
prm -> sd[disk][srnr].n += prm -> sd[disk][srnr].ngaussian[group];
/* Change the gridding method if the flux signum of the point sources differs from what we have in the constant expression */
if (prm -> sd[disk][srnr].gridpoint == &gridpoint_norm) {
if ((prm -> sd[disk][srnr].pf > 0 && ringflux < 0) || (prm -> sd[disk][srnr].pf < 0 && ringflux > 0)) {
prm -> sd[disk][srnr].gridpoint = &gridpoint_mixed;
prm -> sd[disk][srnr].srput = &srput_mixed;
}
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates surface brightness sin component and adds it to the subring */
static void gau_getcloudnumber_pas(void *rpm, int srnr, int group, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* get azimuth from Gaussian descriptors */
static void gau_getaz(ringparms *prm, int pgaip, maths_rstrf *randstr, int pgaid, float *az, float *sinaz, float *cosaz, int srnr, int disk)
{
*az = fmodf(prm -> modpar[pgaip*prm -> nr+srnr]+zprof(1, randstr, &(prm -> sd[disk][srnr].y2))*prm -> sd[disk][srnr].gaudi[pgaid], TWOPI);
while (*az < 0.0)
*az = *az+TWOPI;
/* *az = prm -> modpar[pgaip*prm -> nr+srnr]+zprof(1, randstr)*prm -> sd[disk][srnr].gaudi[pgaid]; */
/* *az = prm -> modpar[(PRPARAMS+disk*NDPARAMS+pgaip)*prm -> nr+srnr]+zprof(1, randstr)*prm -> sd[disk][srnr].gaudi[pgaid]; */
/* az = prm -> modpar[(PRPARAMS+disk*NDPARAMS+pgaip)*prm -> nr+srnr]+zprof(1, randstr)*prm -> modpar[(PRPARAMS+disk*NDPARAMS+pgaid)*prm -> nr+srnr]; */
*sinaz = sinf(*az);
*cosaz = cosf(*az);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* allocates an inf_azi struct */
static inf_azi *create_inf_azi(void)
{
inf_azi *create_inf_azi = NULL;
if (!(create_inf_azi = (inf_azi *) malloc(sizeof(inf_azi))))
return create_inf_azi;
return create_inf_azi;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* deallocates an inf_azi struct */
static int destroy_inf_azi(inf_azi *inf_aziv)
{
if (!(inf_aziv))
return 0;
free(inf_aziv);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm1 struct */
static int chkb_azi(ringparms *rpm, fitparms *fit)
{
int actiflag, disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
actiflag = 0;
if (!(rpm -> inf_aziv[disk]))
if (!(rpm -> inf_aziv[disk] = create_inf_azi()))
return 1;
rpm -> inf_aziv[disk] -> pr0 = &pr_azi_pas;
rpm -> inf_aziv[disk] -> pr1 = &pr_azi_pas;
/* First range */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PAZ1W))) {
rpm -> inf_aziv[disk] -> srpr0 = &srpr_azi_pas;
}
else {
rpm -> inf_aziv[disk] -> srpr0 = &srpr_azi_act;
rpm -> inf_aziv[disk] -> pr0 = &pr_azi_act;
actiflag = 1;
}
/* Second range */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PAZ2W))) {
rpm -> inf_aziv[disk] -> srpr1 = &srpr_azi_pas;
}
else {
rpm -> inf_aziv[disk] -> srpr1 = &srpr_azi_act;
rpm -> inf_aziv[disk] -> pr1 = &pr_azi_act;
actiflag = 1;
}
rpm -> inf_aziv[disk] -> srshape = &srshape_azi_pas;
rpm -> inf_aziv[disk] -> corrp = &corrp_azi_pas;
rpm -> inf_aziv[disk] -> setoutrange = &setoutrange_azi_pas;
if ((actiflag)) {
rpm -> inf_aziv[disk] -> srshape = &srshape_azi_act;
rpm -> inf_aziv[disk] -> corrp = &corrp_azi_act;
rpm -> inf_aziv[disk] -> setoutrange = &setoutrange_azi_act;
}
}
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates Gaussian surface brightness dispersion in rad and adds it to the subring */
static void srpr_azi_act(void *rpm, int srnr, int number, int disk)
{
ringparms *prm;
float azi;
prm = (ringparms *) rpm;
azi = fmodf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PAZ1P+2*number)*prm -> nr+srnr],TWOPI);
while (azi < 0.0)
azi = azi+TWOPI;
prm -> sd[disk][srnr].ranges[number][0] = azi-0.5*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PAZ1W+2*number)*prm -> nr+srnr];
prm -> sd[disk][srnr].ranges[number][1] = azi+0.5*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PAZ1W+2*number)*prm -> nr+srnr];
if (prm -> sd[disk][srnr].ranges[number][1] > TWOPI) {
prm -> sd[disk][srnr].ranges[number][2] = prm -> sd[disk][srnr].ranges[number][0]-TWOPI;
prm -> sd[disk][srnr].ranges[number][3] = prm -> sd[disk][srnr].ranges[number][1]-TWOPI;
}
else {
prm -> sd[disk][srnr].ranges[number][2] = prm -> sd[disk][srnr].ranges[number][0]+TWOPI;
prm -> sd[disk][srnr].ranges[number][3] = prm -> sd[disk][srnr].ranges[number][1]+TWOPI;
}
prm -> sd[disk][srnr].outofrange = 1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void srpr_azi_pas(void *rpm, int srnr, int number, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].outofrange = 0;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Check if azimuth is in allowed range and put switches */
static void pr_azi_pas(float *azi, float ranges[2][4], int *outofrange, int i)
{
/* *outofrange = 0; */
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Check if azimuth is in allowed range and put switches */
static void setoutrange_azi_pas(int *outofrange)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Check if azimuth is in allowed range and put switches */
static void setoutrange_azi_act(int *outofrange)
{
*outofrange = 1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Check if azimuth is in allowed range and put switches */
static void pr_azi_act(float *azi, float ranges[2][4], int *outofrange, int i)
{
/* if ((*outofrange)) { */
/* if (maths_checkinbetwf(ranges[i][0], ranges[i][1], *azi) || maths_checkinbetwf(ranges[i][2], ranges[i][3], *azi)) { */
/* *outofrange = 0; */
/* } */
/* } */
/* Changed to this */
/* *outofrange = 1; */
if (maths_checkinbetwf(ranges[i][0], ranges[i][1], *azi) || maths_checkinbetwf(ranges[i][2], ranges[i][3], *azi)) {
*outofrange = 0;
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static int srshape_azi_act(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
if ((outofrange)) {
maths_rndmf(prm -> sd[disk][srnr].permrandstr);
zprof(prm -> ltype[disk], prm -> sd[disk][srnr].permrandstr, &(prm -> sd[disk][srnr].y2));
/* This shift by 5000000 pixels should do, one could do more elegant, but I'm tired */
pp[1] = 5000000.;
return 1;
}
else {
srshape(prm, pp, sinaz, cosaz, srnr, disk);
}
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static int srshape_azi_pas(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
srshape(prm, pp, sinaz, cosaz, srnr, disk);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static int srshape_azi_actcool(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
if ((outofrange)) {
maths_rndmf(prm -> sd[disk][srnr].permrandstr);
zprof(prm -> ltype[disk], prm -> sd[disk][srnr].permrandstr, &(prm -> sd[disk][srnr].y2));
/* This shift by 5000000 pixels should do, one could do more elegant, but I'm tired */
pp[1] = 5000000.;
return 1;
}
else {
srshapecool(prm, pp, sinaz, cosaz, srnr, disk);
}
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static int srshape_azi_pascool(void *rpm, float *pp, float sinaz, float cosaz, int srnr, int outofrange, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
srshapecool(prm, pp, sinaz, cosaz, srnr, disk);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static void corrp_azi_act(void *rpm, int srnr, int *outofrange, int signum)
{
/* ringparms *prm; */
/* prm = (ringparms *) rpm; */
/* if ((*outofrange)) { */
/* --prm -> sd[disk][srnr].outn; */
/* } */
*outofrange = 1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Generation of a pointsource list */
static void corrp_azi_pas(void *rpm, int srnr, int *outofrange, int signum)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_vrad struct */ static inf_vrad *create_inf_vrad(void) { inf_vrad *create_inf_vrad= NULL; if (!(create_inf_vrad = (inf_vrad *) malloc(sizeof(inf_vrad)))) return create_inf_vrad; return create_inf_vrad; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_vver struct */ static inf_vver *create_inf_vver(void) { inf_vver *create_inf_vver= NULL; if (!(create_inf_vver = (inf_vver *) malloc(sizeof(inf_vver)))) return create_inf_vver; return create_inf_vver; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_dvro struct */ static inf_dvro *create_inf_dvro(void) { inf_dvro *create_inf_dvro= NULL; if (!(create_inf_dvro = (inf_dvro *) malloc(sizeof(inf_dvro)))) return create_inf_dvro; return create_inf_dvro; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_dvra struct */ static inf_dvra *create_inf_dvra(void) { inf_dvra *create_inf_dvra= NULL; if (!(create_inf_dvra = (inf_dvra *) malloc(sizeof(inf_dvra)))) return create_inf_dvra; return create_inf_dvra; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_dvve struct */ static inf_dvve *create_inf_dvve(void) { inf_dvve *create_inf_dvve= NULL; if (!(create_inf_dvve = (inf_dvve *) malloc(sizeof(inf_dvve)))) return create_inf_dvve; return create_inf_dvve; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_vm0 struct */ static inf_vm0 *create_inf_vm0(void) { inf_vm0 *create_inf_vm0= NULL; if (!(create_inf_vm0 = (inf_vm0 *) malloc(sizeof(inf_vm0)))) return create_inf_vm0; return create_inf_vm0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_vm1 struct */ static inf_vm1 *create_inf_vm1(void) { inf_vm1 *create_inf_vm1 = NULL; if (!(create_inf_vm1 = (inf_vm1 *) malloc(sizeof(inf_vm1)))) return create_inf_vm1; return create_inf_vm1; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_vm2 struct */ static inf_vm2 *create_inf_vm2(void) { inf_vm2 *create_inf_vm2 = NULL; if (!(create_inf_vm2 = (inf_vm2 *) malloc(sizeof(inf_vm2)))) return create_inf_vm2; return create_inf_vm2; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_vm3 struct */ static inf_vm3 *create_inf_vm3(void) { inf_vm3 *create_inf_vm3 = NULL; if (!(create_inf_vm3 = (inf_vm3 *) malloc(sizeof(inf_vm3)))) return create_inf_vm3; return create_inf_vm3; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_vm4 struct */ static inf_vm4 *create_inf_vm4(void) { inf_vm4 *create_inf_vm4 = NULL; if (!(create_inf_vm4 = (inf_vm4 *) malloc(sizeof(inf_vm4)))) return create_inf_vm4; return create_inf_vm4; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ra1 struct */ static inf_ra1 *create_inf_ra1(void) { inf_ra1 *create_inf_ra1 = NULL; if (!(create_inf_ra1 = (inf_ra1 *) malloc(sizeof(inf_ra1)))) return create_inf_ra1; return create_inf_ra1; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ra2 struct */ static inf_ra2 *create_inf_ra2(void) { inf_ra2 *create_inf_ra2 = NULL; if (!(create_inf_ra2 = (inf_ra2 *) malloc(sizeof(inf_ra2)))) return create_inf_ra2; return create_inf_ra2; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ra3 struct */ static inf_ra3 *create_inf_ra3(void) { inf_ra3 *create_inf_ra3 = NULL; if (!(create_inf_ra3 = (inf_ra3 *) malloc(sizeof(inf_ra3)))) return create_inf_ra3; return create_inf_ra3; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ra4 struct */ static inf_ra4 *create_inf_ra4(void) { inf_ra4 *create_inf_ra4 = NULL; if (!(create_inf_ra4 = (inf_ra4 *) malloc(sizeof(inf_ra4)))) return create_inf_ra4; return create_inf_ra4; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ro1 struct */ static inf_ro1 *create_inf_ro1(void) { inf_ro1 *create_inf_ro1 = NULL; if (!(create_inf_ro1 = (inf_ro1 *) malloc(sizeof(inf_ro1)))) return create_inf_ro1; return create_inf_ro1; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ro2 struct */ static inf_ro2 *create_inf_ro2(void) { inf_ro2 *create_inf_ro2 = NULL; if (!(create_inf_ro2 = (inf_ro2 *) malloc(sizeof(inf_ro2)))) return create_inf_ro2; return create_inf_ro2; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ro3 struct */ static inf_ro3 *create_inf_ro3(void) { inf_ro3 *create_inf_ro3 = NULL; if (!(create_inf_ro3 = (inf_ro3 *) malloc(sizeof(inf_ro3)))) return create_inf_ro3; return create_inf_ro3; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ro4 struct */ static inf_ro4 *create_inf_ro4(void) { inf_ro4 *create_inf_ro4 = NULL; if (!(create_inf_ro4 = (inf_ro4 *) malloc(sizeof(inf_ro4)))) return create_inf_ro4; return create_inf_ro4; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_wm0 struct */ static inf_wm0 *create_inf_wm0 (void) { inf_wm0 *create_inf_wm0 = NULL; if (!(create_inf_wm0 = (inf_wm0 *) malloc(sizeof(inf_wm0 )))) return create_inf_wm0 ; return create_inf_wm0 ; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_wm1 struct */ static inf_wm1 *create_inf_wm1 (void) { inf_wm1 *create_inf_wm1 = NULL; if (!(create_inf_wm1 = (inf_wm1 *) malloc(sizeof(inf_wm1 )))) return create_inf_wm1 ; return create_inf_wm1 ; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_wm2 struct */ static inf_wm2 *create_inf_wm2 (void) { inf_wm2 *create_inf_wm2 = NULL; if (!(create_inf_wm2 = (inf_wm2 *) malloc(sizeof(inf_wm2 )))) return create_inf_wm2 ; return create_inf_wm2 ; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_wm3 struct */ static inf_wm3 *create_inf_wm3 (void) { inf_wm3 *create_inf_wm3 = NULL; if (!(create_inf_wm3 = (inf_wm3 *) malloc(sizeof(inf_wm3 )))) return create_inf_wm3 ; return create_inf_wm3 ; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_wm4 struct */ static inf_wm4 *create_inf_wm4 (void) { inf_wm4 *create_inf_wm4 = NULL; if (!(create_inf_wm4 = (inf_wm4 *) malloc(sizeof(inf_wm4 )))) return create_inf_wm4 ; return create_inf_wm4 ; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_ls0 struct */ static inf_ls0 *create_inf_ls0 (void) { inf_ls0 *create_inf_ls0 = NULL; if (!(create_inf_ls0 = (inf_ls0 *) malloc(sizeof(inf_ls0 )))) return create_inf_ls0 ; return create_inf_ls0 ; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* allocates an inf_lc0 struct */ static inf_lc0 *create_inf_lc0 (void) { inf_lc0 *create_inf_lc0 = NULL; if (!(create_inf_lc0 = (inf_lc0 *) malloc(sizeof(inf_lc0 )))) return create_inf_lc0 ; return create_inf_lc0 ; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm0 struct */ static int destroy_inf_vrad (inf_vrad *int_vradv ) { if (!(int_vradv )) return 0; free(int_vradv ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm0 struct */ static int destroy_inf_vver (inf_vver *int_vverv ) { if (!(int_vverv )) return 0; free(int_vverv ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm0 struct */ static int destroy_inf_dvro (inf_dvro *int_dvrov ) { if (!(int_dvrov )) return 0; free(int_dvrov ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm0 struct */ static int destroy_inf_dvra (inf_dvra *int_dvrav ) { if (!(int_dvrav )) return 0; free(int_dvrav ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm0 struct */ static int destroy_inf_dvve (inf_dvve *int_dvvev ) { if (!(int_dvvev )) return 0; free(int_dvvev ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm0 struct */ static int destroy_inf_vm0 (inf_vm0 *int_vm0v ) { if (!(int_vm0v )) return 0; free(int_vm0v ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm1 struct */ static int destroy_inf_vm1(inf_vm1 *int_vm1v) { if (!(int_vm1v)) return 0; free(int_vm1v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm2 struct */ static int destroy_inf_vm2(inf_vm2 *int_vm2v) { if (!(int_vm2v)) return 0; free(int_vm2v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm3 struct */ static int destroy_inf_vm3(inf_vm3 *int_vm3v) { if (!(int_vm3v)) return 0; free(int_vm3v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_vm4 struct */ static int destroy_inf_vm4(inf_vm4 *int_vm4v) { if (!(int_vm4v)) return 0; free(int_vm4v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ra1 struct */ static int destroy_inf_ra1(inf_ra1 *int_ra1v) { if (!(int_ra1v)) return 0; free(int_ra1v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ra2 struct */ static int destroy_inf_ra2(inf_ra2 *int_ra2v) { if (!(int_ra2v)) return 0; free(int_ra2v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ra3 struct */ static int destroy_inf_ra3(inf_ra3 *int_ra3v) { if (!(int_ra3v)) return 0; free(int_ra3v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ra4 struct */ static int destroy_inf_ra4(inf_ra4 *int_ra4v) { if (!(int_ra4v)) return 0; free(int_ra4v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ro1 struct */ static int destroy_inf_ro1(inf_ro1 *int_ro1v) { if (!(int_ro1v)) return 0; free(int_ro1v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ro2 struct */ static int destroy_inf_ro2(inf_ro2 *int_ro2v) { if (!(int_ro2v)) return 0; free(int_ro2v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ro3 struct */ static int destroy_inf_ro3(inf_ro3 *int_ro3v) { if (!(int_ro3v)) return 0; free(int_ro3v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ro4 struct */ static int destroy_inf_ro4(inf_ro4 *int_ro4v) { if (!(int_ro4v)) return 0; free(int_ro4v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_wm0 struct */ static int destroy_inf_wm0 (inf_wm0 *int_wm0v ) { if (!(int_wm0v )) return 0; free(int_wm0v ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_wm1 struct */ static int destroy_inf_wm1(inf_wm1 *int_wm1v) { if (!(int_wm1v)) return 0; free(int_wm1v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_wm2 struct */ static int destroy_inf_wm2(inf_wm2 *int_wm2v) { if (!(int_wm2v)) return 0; free(int_wm2v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_wm3 struct */ static int destroy_inf_wm3(inf_wm3 *int_wm3v) { if (!(int_wm3v)) return 0; free(int_wm3v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_wm4 struct */ static int destroy_inf_wm4(inf_wm4 *int_wm4v) { if (!(int_wm4v)) return 0; free(int_wm4v); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_ls0 struct */ static int destroy_inf_ls0 (inf_ls0 *int_ls0v ) { if (!(int_ls0v )) return 0; free(int_ls0v ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ /* deallocates an inf_lc0 struct */ static int destroy_inf_lc0 (inf_lc0 *int_lc0v ) { if (!(int_lc0v )) return 0; free(int_lc0v ); return 0; } /* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Initialises the rng internal to the calulation of sdis */
static void rndmf_init_sdis_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].siseed[0] = prm -> iseed2+1+disk;
prm -> sd[disk][srnr].siseed[1] = srnr;
/* Reset things */
maths_rndmf_init(prm -> sd[disk][srnr].siseed, prm -> sd[disk][srnr].srandstr);
zprof(6, prm -> sd[disk][srnr].srandstr, &(prm -> sd[disk][srnr].y2));
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function doing nothing instead of rndmf_init_sdis_act */
static void rndmf_init_sdis_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Re-calculates point source numbers and fluxes depending on sub-cloud number */
static void chclfl_sdis_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
int clouds;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].nsubcl = (clouds = roundnormal(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PCLNR)*prm -> nr+srnr])) > 0?clouds:1;
prm -> sd[disk][srnr].nsubclinv = 1.0/((float) prm -> sd[disk][srnr].nsubcl);
prm -> sd[disk][srnr].pf = prm -> sd[disk][srnr].pf*prm -> sd[disk][srnr].nsubclinv;
prm -> sd[disk][srnr].nharmnorm = prm -> sd[disk][srnr].nharmnorm*prm -> sd[disk][srnr].nsubcl;
prm -> sd[disk][srnr].ngaussian[0] = prm -> sd[disk][srnr].ngaussian[0]*prm -> sd[disk][srnr].nsubcl;
prm -> sd[disk][srnr].ngaussian[1] = prm -> sd[disk][srnr].ngaussian[1]*prm -> sd[disk][srnr].nsubcl;
prm -> sd[disk][srnr].ngaussian[2] = prm -> sd[disk][srnr].ngaussian[2]*prm -> sd[disk][srnr].nsubcl;
prm -> sd[disk][srnr].ngaussian[3] = prm -> sd[disk][srnr].ngaussian[3]*prm -> sd[disk][srnr].nsubcl;
prm -> sd[disk][srnr].n = prm -> sd[disk][srnr].n *prm -> sd[disk][srnr].nsubcl;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Re-calculates point source numbers and fluxes depending on sub-cloud number */
static void chclfl_sdis_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* LOOK HERE */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Initialises the rng internal to the calulation of sdis */
static void rndmf_init_smi_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].iseed[0] = prm -> iseed2+2+disk;
prm -> sd[disk][srnr].iseed[1] = srnr+1;
/* Reset the rng */
maths_rndmf_init(prm -> sd[disk][srnr].iseed, prm -> sd[disk][srnr].randstr);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function doing nothing instead of rndmf_init_sdis_act */
static void rndmf_init_smi_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_sdis_act */
static void pr_sdis_pas(void *rpm, float *v, float *vold, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates random velocity component and adds it to the input */
static void pr_sdis_act(void *rpm, float *v, float *vold, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*vold = *v;
*v = *v+zprof(1, prm -> sd[disk][srnr].srandstr, &(prm -> sd[disk][srnr].y2))*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSDIS)*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates random velocity component and adds it to the input, repeats the process a few times */
static void sdis_repeater_act(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk)
{
ringparms *prm;
int i;
prm = (ringparms *) rpm;
for (i = 1; i < prm -> sd[disk][srnr].nsubcl; ++i) {
pp[5] = vold+zprof(1, prm -> sd[disk][srnr].srandstr, &(prm -> sd[disk][srnr].y2))*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSDIS)*prm -> nr+srnr];
#ifdef PBCORR
(*(prm -> sd[disk][srnr].gridpoint))(hdr, prm -> fill_pbcfac, prm -> modpar, prm -> nr, prm -> sd, srnr, j, pp, signum, npoints, disk);
#else
(*(prm -> sd[disk][srnr].gridpoint))(hdr, prm -> modpar, prm -> nr, prm -> sd, srnr, j, pp, signum, npoints, disk);
#endif
(*(prm -> inf_aziv[disk] -> corrp))(rpm, srnr, &(prm -> sd[disk][srnr].outofrange), signum);
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy */
static void sdis_repeater_pas(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates random velocity component and adds it to the input, repeats the process a few times */
static void sdis_repeater_actcool(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk)
{
ringparms *prm;
int i;
prm = (ringparms *) rpm;
for (i = 1; i < prm -> sd[disk][srnr].nsubcl; ++i) {
/* pp[5] = vold+zprof(1, prm -> sd[disk][srnr].srandstr, &(prm -> sd[disk][srnr].y2))*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PSDIS)*prm -> nr+srnr]; */
#ifdef PBCORR
(*(prm -> sd[disk][srnr].gridpoint))(hdr, prm -> fill_pbcfac, prm -> modpar, prm -> nr, prm -> sd, srnr, j, pp, signum, npoints, disk);
#else
(*(prm -> sd[disk][srnr].gridpoint))(hdr, prm -> modpar, prm -> nr, prm -> sd, srnr, j, pp, signum, npoints, disk);
#endif
(*(prm -> inf_aziv[disk] -> corrp))(rpm, srnr, &(prm -> sd[disk][srnr].outofrange), signum);
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy */
static void sdis_repeater_pascool(void *rpm, float *pp, float vold, int srnr, hdrinf *hdr, long *j, int signum, long *npoints, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_sdis_act */
static void pr_sdis_empty_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates random velocity component and adds it to the input */
static void pr_sdis_empty_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
int i;
prm = (ringparms *) rpm;
for (i = 0; i < prm -> sd[disk][srnr].nsubcl; ++i)
zprof(1, prm -> sd[disk][srnr].srandstr, &(prm -> sd[disk][srnr].y2));
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vrad_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVRAD)*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void pr_vrad_pas(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a vertical velocity component and adds it to the input */
static void pr_vver_act(void *rpm, float *point, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
/* Now, this is a bit more complex */
if (point[2] > 0.0)
point[5] = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVVER)*prm -> nr+srnr];
else
point[5] = -prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVVER)*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void pr_vver_pas(void *rpm, float *point, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vver_rota_act(void *rpm, float *vz, float *vz2, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*vz2 = *vz2+*vz*prm -> sd[disk][srnr].cosi;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void pr_vver_rota_pas(void *rpm, float *vz, float *vz2, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_dvro_act(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
point[4] = point[4]+cosaz*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVRO)*prm -> nr+srnr]*fabs(point[2]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input, starting at zdro */
static void pr_dvro_act2(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
if (fabs(point[2]) >= fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PZDRO)*prm -> nr+srnr])) {
point[4] = point[4]+cosaz*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVRO)*prm -> nr+srnr]*(fabs(point[2])-fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PZDRO)*prm -> nr+srnr]));
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void pr_dvro_pas(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_dvra_act(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
point[4] = point[4]+sinaz*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVRA)*prm -> nr+srnr]*fabs(point[2]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input, starting at zdra */
static void pr_dvra_act2(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
if (fabs(point[2]) > fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PZDRA)*prm -> nr+srnr]))
point[4] = point[4]+sinaz*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVRA)*prm -> nr+srnr]*(fabs(point[2]) - fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVRA)*prm -> nr+srnr]));
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void pr_dvra_pas(void *rpm, float *point, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_dvve_act(void *rpm, float *point, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
/* Now, this should do, the signum of the z-component is the signum of z */
point[5] = point[5]+prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVVE)*prm -> nr+srnr]*point[2];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input, if the scale height is above a certain value */
static void pr_dvve_act2(void *rpm, float *point, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
/* Now, this should do, the signum of the z-component is the signum of z */
if (fabs(point[2]) > fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PZDVE)*prm -> nr+srnr])) {
if (point[2] > 0.0)
point[5] = point[5]+prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVVE)*prm -> nr+srnr]*(point[2]-fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PZDVE)*prm -> nr+srnr]));
else
point[5] = point[5]+prm -> modpar[(PRPARAMS+disk*NDPARAMS+PDVVE)*prm -> nr+srnr]*(point[2]+fabs(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PZDVE)*prm -> nr+srnr]));
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Dummy */
static void pr_dvve_pas(void *rpm, float *point, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function */
static void srpr_vmi_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm1s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vps1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM1A)*prm -> nr+srnr]*sinf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm1c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vpc1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM1A)*prm -> nr+srnr]*cosf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm2s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vps2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM2A)*prm -> nr+srnr]*sinf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm2c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vpc2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM2A)*prm -> nr+srnr]*cosf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm3s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vps3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM3A)*prm -> nr+srnr]*sinf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm3c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vpc3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM3A)*prm -> nr+srnr]*cosf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm4s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vps4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM4A)*prm -> nr+srnr]*sinf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_vm4c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].vpc4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM4A)*prm -> nr+srnr]*cosf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_vmis/c_act */
static void pr_vmi_pas(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm0_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+prm -> modpar[(PRPARAMS+disk*NDPARAMS+PVM0A)*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm1s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*prm -> sd[disk][srnr].vps1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm2s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+(2.0*sinaz*cosaz)* prm -> sd[disk][srnr].vps2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm3s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+(3.0*sinaz-4.0*sinaz*sinaz*sinaz)*prm -> sd[disk][srnr].vps3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm4s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+(8.0*sinaz*cosaz*cosaz*cosaz-4.0*sinaz*cosaz)* prm -> sd[disk][srnr].vps4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm1c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz* prm -> sd[disk][srnr].vpc1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm2c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+(1.0-2.0*sinaz*sinaz)*prm -> sd[disk][srnr].vpc2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm3c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+(4.0*cosaz*cosaz*cosaz-3.0*cosaz)*prm -> sd[disk][srnr].vpc3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_vm4c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+(8.0*cosaz*cosaz*cosaz*cosaz-8.0*cosaz*cosaz+1.0)*prm -> sd[disk][srnr].vpc4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function */
static void srpr_rai_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra1s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ras1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA1A)*prm -> nr+srnr]*sinf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra1c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].rac1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA1A)*prm -> nr+srnr]*cosf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra2s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ras2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA2A)*prm -> nr+srnr]*sinf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra2c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].rac2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA2A)*prm -> nr+srnr]*cosf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra3s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ras3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA3A)*prm -> nr+srnr]*sinf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra3c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].rac3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA3A)*prm -> nr+srnr]*cosf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra4s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ras4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA4A)*prm -> nr+srnr]*sinf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ra4c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].rac4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA4A)*prm -> nr+srnr]*cosf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRA4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_rais/c_act */
static void pr_rai_pas(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra1s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*sinaz*prm -> sd[disk][srnr].ras1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra2s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*(2.0*sinaz*cosaz)* prm -> sd[disk][srnr].ras2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra3s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*(3.0*sinaz-4.0*sinaz*sinaz*sinaz)*prm -> sd[disk][srnr].ras3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra4s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*(8.0*sinaz*cosaz*cosaz*cosaz-4.0*sinaz*cosaz)* prm -> sd[disk][srnr].ras4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra1c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*cosaz* prm -> sd[disk][srnr].rac1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra2c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*(1.0-2.0*sinaz*sinaz)*prm -> sd[disk][srnr].rac2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra3c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*(4.0*cosaz*cosaz*cosaz-3.0*cosaz)*prm -> sd[disk][srnr].rac3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ra4c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+sinaz*(8.0*cosaz*cosaz*cosaz*cosaz-8.0*cosaz*cosaz+1.0)*prm -> sd[disk][srnr].rac4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function */
static void srpr_roi_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro1s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ros1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO1A)*prm -> nr+srnr]*sinf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro1c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].roc1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO1A)*prm -> nr+srnr]*cosf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro2s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ros2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO2A)*prm -> nr+srnr]*sinf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro2c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].roc2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO2A)*prm -> nr+srnr]*cosf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro3s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ros3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO3A)*prm -> nr+srnr]*sinf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro3c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].roc3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO3A)*prm -> nr+srnr]*cosf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro4s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].ros4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO4A)*prm -> nr+srnr]*sinf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates velocity sin component and adds it to the subring */
static void srpr_ro4c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].roc4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO4A)*prm -> nr+srnr]*cosf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PRO4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_rois/c_act */
static void pr_roi_pas(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro1s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*sinaz*prm -> sd[disk][srnr].ros1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro2s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*(2.0*sinaz*cosaz)* prm -> sd[disk][srnr].ros2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro3s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*(3.0*sinaz-4.0*sinaz*sinaz*sinaz)*prm -> sd[disk][srnr].ros3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro4s_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*(8.0*sinaz*cosaz*cosaz*cosaz-4.0*sinaz*cosaz)* prm -> sd[disk][srnr].ros4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro1c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*cosaz* prm -> sd[disk][srnr].roc1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro2c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*(1.0-2.0*sinaz*sinaz)*prm -> sd[disk][srnr].roc2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro3c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*(4.0*cosaz*cosaz*cosaz-3.0*cosaz)*prm -> sd[disk][srnr].roc3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ro4c_act(void *rpm, float *v, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*v = *v+cosaz*(8.0*cosaz*cosaz*cosaz*cosaz-8.0*cosaz*cosaz+1.0)*prm -> sd[disk][srnr].roc4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp sin component and adds it to the subring */
static void srpr_wm1s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wps1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM1A)*prm -> nr+srnr]*sinf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy function */
static void srpr_wmi_pas(void *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp cos component and adds it to the subring */
static void srpr_wm1c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wpc1 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM1A)*prm -> nr+srnr]*cosf(prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM1P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp sin component and adds it to the subring */
static void srpr_wm2s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wps2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM2A)*prm -> nr+srnr]*sinf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp cos component and adds it to the subring */
static void srpr_wm2c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wpc2 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM2A)*prm -> nr+srnr]*cosf(2.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM2P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp sin component and adds it to the subring */
static void srpr_wm3s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wps3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM3A)*prm -> nr+srnr]*sinf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp cos component and adds it to the subring */
static void srpr_wm3c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wpc3 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM3A)*prm -> nr+srnr]*cosf(3.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM3P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp sin component and adds it to the subring */
static void srpr_wm4s_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wps4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM4A)*prm -> nr+srnr]*sinf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates warp cos component and adds it to the subring */
static void srpr_wm4c_act(void *rpm, int srnr, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
prm -> sd[disk][srnr].wpc4 = prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM4A)*prm -> nr+srnr]*cosf(4.0*prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM4P)*prm -> nr+srnr]);
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_wmis/c_act */
static void pr_wmi_pas(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp m=0 component and adds it to the input */
static void pr_wm0_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+prm -> modpar[(PRPARAMS+disk*NDPARAMS+PWM0A)*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm1s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+sinaz*prm -> sd[disk][srnr].wps1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm2s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+(2.0*sinaz*cosaz)* prm -> sd[disk][srnr].wps2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm3s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+(3.0*sinaz-4.0*sinaz*sinaz*sinaz)*prm -> sd[disk][srnr].wps3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm4s_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+(8.0*sinaz*cosaz*cosaz*cosaz-4.0*sinaz*cosaz)* prm -> sd[disk][srnr].wps4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm1c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+cosaz* prm -> sd[disk][srnr].wpc1;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm2c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+(1.0-2.0*sinaz*sinaz)*prm -> sd[disk][srnr].wpc2;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm3c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+(4.0*cosaz*cosaz*cosaz-3.0*cosaz)*prm -> sd[disk][srnr].wpc3;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a warp component and adds it to the input */
static void pr_wm4c_act(void *rpm, float *z, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*z = *z+(8.0*cosaz*cosaz*cosaz*cosaz-8.0*cosaz*cosaz+1.0)*prm -> sd[disk][srnr].wpc4;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_ls0_act */
static void pr_ls0_pas(void *rpm, float *y, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_ls0_act(void *rpm, float *y, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*y = *y+prm -> modpar[(PRPARAMS+disk*NDPARAMS+PLS0)*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* dummy instead of pr_lc0_act */
static void pr_lc0_pas(void *rpm, float *x, int srnr, float sinaz, float cosaz, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* calculates a radial velocity component and adds it to the input */
static void pr_lc0_act(void *rpm, float *x, int srnr, float sinaz, float cosaz, int disk)
{
ringparms *prm;
prm = (ringparms *) rpm;
*x = *x+prm -> modpar[(PRPARAMS+disk*NDPARAMS+PLC0)*prm -> nr+srnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* wrapper to call userdble_c from gipsy */
static int userdble_tir(simparse_scn_arel **arel, double *anarray, int *elements, int *defaultstat, char *keyword, char *message)
{
int nread, nreturned, keypres;
double *retarray = NULL;
int i;
int ndef = 0, min = 0, max = -1, keyreq = 0, ltmax = 0;
/*
def 0/1: no default/default
def 2: hidden
def 4 exact number
from doc:
All these routines are integer functions which return the number of items entered by the user
0 --- no default is possible
1 --- user is prompted, but default is taken when user types RETURN
2 --- user is not prompted and default is taken unless the input was pre-specified
4 --- (added to any of the above values) the user is required to enter the exact number of items
*/
min = *elements;
max = *elements;
if (*defaultstat & 1) {
/* user is prompted, but default is taken when user types RETURN: keyreq = 1 */
ndef = *elements; keyreq = 1; ltmax = 0;
}
else {
/* No default is possible: */
ndef = 0; keyreq = 1; ltmax = 0;
}
if (*defaultstat & 2) {
/* user is not prompted and default is taken unless the input was pre-specified */
ndef = *elements; keyreq = 0; ltmax = 0;
}
if (*defaultstat & 4) {
/* the user is required to enter the exact number of items */
ndef = 0; ltmax = 1;
}
if (simparse_scn_arel_readval_double(arel, keyword, message, ndef, anarray, min, max, keyreq, ltmax, &keypres, &nread, &nreturned, &retarray)) {
if (retarray)
free(retarray);
return -1;
}
nreturned = (nreturned > *elements)?*elements:nreturned;
for (i = 0; i < nreturned; ++i)
anarray[i] = retarray[i];
if (retarray) {
free(retarray);
}
return nread;
/* fint felements, fdefaultstat; */
/* int userdble_tir; */
/* felements = (fint) *elements; */
/* fdefaultstat = (fint) *defaultstat; */
/* userdble_tir = (int) userdble_c(anarray, &felements, &fdefaultstat, tofchar(keyword), tofchar(message)); */
/* *elements = (int) felements; */
/* *defaultstat = (int) fdefaultstat; */
/* return userdble_tir; */
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* wrapper to call userreal_c from gipsy */
static int userreal_tir(simparse_scn_arel **arel, float *anarray, int *elements, int *defaultstat, char *keyword, char *message)
{
int nread, nreturned, keypres;
float *retarray = NULL;
int i;
int ndef = 0, min = 0, max = -1, keyreq = 0, ltmax = 0;
/*
def 0/1: no default/default
def 2: hidden
def 4 exact number
from doc:
All these routines are integer functions which return the number of items entered by the user
0 --- no default is possible
1 --- user is prompted, but default is taken when user types RETURN
2 --- user is not prompted and default is taken unless the input was pre-specified
4 --- (added to any of the above values) the user is required to enter the exact number of items
*/
min = *elements;
max = *elements;
if (*defaultstat & 1) {
/* user is prompted, but default is taken when user types RETURN: keyreq = 1 */
ndef = *elements; keyreq = 1; ltmax = 0;
}
else {
/* No default is possible: */
ndef = 0; keyreq = 1; ltmax = 0;
}
if (*defaultstat & 2) {
/* user is not prompted and default is taken unless the input was pre-specified */
ndef = *elements; keyreq = 0; ltmax = 0;
}
if (*defaultstat & 4) {
/* the user is required to enter the exact number of items */
ndef = 0; ltmax = 1;
}
if (simparse_scn_arel_readval_float(arel, keyword, message, ndef, anarray, min, max, keyreq, ltmax, &keypres, &nread, &nreturned, &retarray)) {
if (retarray)
free(retarray);
return -1;
}
nreturned = (nreturned > *elements)?*elements:nreturned;
for (i = 0; i < nreturned; ++i)
anarray[i] = retarray[i];
if (retarray) {
free(retarray);
}
return nread;
/* fint felements, fdefaultstat; */
/* int userreal_tir; */
/* felements = (fint) *elements; */
/* fdefaultstat = (fint) *defaultstat; */
/* userreal_tir = (int) userreal_c(anarray, &felements, &fdefaultstat, tofchar(keyword), tofchar(message)); */
/* *elements = (int) felements; */
/* *defaultstat = (int) fdefaultstat; */
/* return userreal_tir; */
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* wrapper to imitate userint_c from gipsy */
static int userint_tir(simparse_scn_arel **arel, int *anarray, int *elements, int *defaultstat, char *keyword, char *message)
{
int nread, nreturned, keypres;
int *retarray = NULL;
int i;
int ndef = 0, min = 0, max = -1, keyreq = 0, ltmax = 0;
/*
def 0/1: no default/default
def 2: hidden
def 4 exact number
from doc:
All these routines are integer functions which return the number of items entered by the user
0 --- no default is possible
1 --- user is prompted, but default is taken when user types RETURN
2 --- user is not prompted and default is taken unless the input was pre-specified
4 --- (added to any of the above values) the user is required to enter the exact number of items
*/
min = *elements;
max = *elements;
if (*defaultstat & 1) {
/* user is prompted, but default is taken when user types RETURN: keyreq = 1 */
ndef = *elements; keyreq = 1; ltmax = 0;
}
else {
/* No default is possible: */
ndef = 0; keyreq = 1; ltmax = 0;
}
if (*defaultstat & 2) {
/* user is not prompted and default is taken unless the input was pre-specified */
ndef = *elements; keyreq = 0; ltmax = 0;
}
if (*defaultstat & 4) {
/* the user is required to enter the exact number of items */
ndef = 0; ltmax = 1;
}
if (simparse_scn_arel_readval_int(arel, keyword, message, ndef, anarray, min, max, keyreq, ltmax, &keypres, &nread, &nreturned, &retarray)) {
if (retarray)
free(retarray);
return -1;
}
nreturned = (nreturned > *elements)?*elements:nreturned;
for (i = 0; i < nreturned; ++i)
anarray[i] = retarray[i];
if (retarray) {
free(retarray);
}
/* I think it's this silly choice */
/* All these routines are integer functions which return the number of items entered by the user. */
return nread;
/* fint *fanarray, felements, fdefaultstat; */
/* int i, userint_tir; */
/* if (*elements > 0){ */
/* if (!(fanarray = (fint *) malloc(*elements*sizeof(fint)))) */
/* return -1; */
/* } */
/* else */
/* fanarray = NULL; */
/* for (i = 0; i < *elements; ++i) { */
/* fanarray[i] = (fint) anarray[i]; */
/* } */
/* felements = (fint) *elements; */
/* fdefaultstat = (fint) *defaultstat; */
/* userint_tir = (int) userint_c(fanarray, &felements, &fdefaultstat, tofchar(keyword), tofchar(message)); */
/* for (i = 0; i < *elements; ++i) { */
/* anarray[i] = (int) fanarray[i]; */
/* } */
/* *elements = (int) felements; */
/* *defaultstat = (int) fdefaultstat; */
/* return userint_tir; */
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* wrapper to call error_c from gipsy */
static int error_tir(int *device, char *message)
{
/* fint fdevice; */
/* fdevice = (fint) *device; */
/* error_c(&fdevice, tofchar(message)); */
/* *device = (int) fdevice; */
fprintf(stderr, "shitty%s\n", message);
if (*device == 4) {
exit(1);
}
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* wrapper to call anyout_c from gipsy */
static int anyout_tir(int *device, char *message)
{
/* fint fdevice; */
/* fdevice = (fint) *device; */
/* anyout_c(&fdevice, tofchar(message)); */
/* *device = (int) fdevice; */
printf("%s\n", message);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* wrapper to call anyout_c from gipsy */
/* static int anyout_cor(FILE *device, char *message) */
/* { */
/* if ((device)) */
/* fprintf(device, "%s\n", message); */
/* else */
/* printf("%s\n", message); */
/* return 0; */
/* } */
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* wrapper to call cancel_c from gipsy */
static int cancel_tir(simparse_scn_arel **arelv, char *parname, int depth)
{
/* cancel_c(tofchar(parname)); */
simparse_scn_arel_deepcancelkey(arelv, parname, depth);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the sdis struct */
static int chkb_sdis(ringparms *rpm, fitparms *fit)
{
int disk, srnr;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the sdis struct */
if (!rpm -> inf_sdisv[disk])
if (!(rpm -> inf_sdisv[disk] = create_inf_sdis()))
return 1;
rpm -> inf_sdisv[disk] -> repeater = &sdis_repeater_pas;
rpm -> inf_sdisv[disk] -> chclfl = &chclfl_sdis_pas;
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PSDIS))) {
/* We point to the right functions */
rpm -> inf_sdisv[disk] -> rndmf_init = &rndmf_init_sdis_pas;
rpm -> inf_sdisv[disk] -> pr = &pr_sdis_pas;
rpm -> inf_sdisv[disk] -> pr_empty = &pr_sdis_empty_pas;
}
else {
/* we allocate the rng */
for (srnr = 0; srnr < rpm -> nr; ++srnr) {
if (!(rpm -> sd[disk][srnr].srandstr))
if (!(rpm -> sd[disk][srnr].srandstr = (maths_rstrf *) malloc(sizeof(maths_rstrf))))
goto error;
}
/* We point to the right functions */
rpm -> inf_sdisv[disk] -> rndmf_init = &rndmf_init_sdis_act;
rpm -> inf_sdisv[disk] -> pr = &pr_sdis_act;
rpm -> inf_sdisv[disk] -> pr_empty = &pr_sdis_empty_act;
/* Do we fit more than one subcloud ? */
if (!(chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PCLNR))) {
rpm -> inf_sdisv[disk] -> repeater = &sdis_repeater_act;
rpm -> inf_sdisv[disk] -> chclfl = &chclfl_sdis_act;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_sdis(rpm -> inf_sdisv[disk]);
rpm -> inf_sdisv[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm0 struct */
static int chkb_vrad(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the vrad struct */
if (!(rpm -> inf_vradv[disk]))
if (!(rpm -> inf_vradv[disk] = create_inf_vrad()))
goto error;
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVRAD))) {
/* We point to the right functions */
rpm -> inf_vradv[disk] -> pr = &pr_vrad_pas;
}
else {
/* We point to the right functions */
rpm -> inf_vradv[disk] -> pr = &pr_vrad_act;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_vrad(rpm -> inf_vradv[disk]);
rpm -> inf_vradv[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm0 struct */
static int chkb_vver(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the vver struct */
if (!(rpm -> inf_vverv[disk])) {
if (!(rpm -> inf_vverv[disk] = create_inf_vver()))
goto error;
}
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVVER))) {
/* We point to the right functions */
rpm -> inf_vverv[disk] -> pr = &pr_vver_pas;
rpm -> inf_vverv[disk] -> pr_rota = &pr_vver_rota_pas;
}
else {
/* We point to the right functions */
rpm -> inf_vverv[disk] -> pr = &pr_vver_act;
rpm -> inf_vverv[disk] -> pr_rota = &pr_vver_rota_act;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_vver(rpm -> inf_vverv[disk]);
rpm -> inf_vverv[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm0 struct */
static int chkb_dvro(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the dvro struct */
if (!(rpm -> inf_dvrov[disk]))
if (!(rpm -> inf_dvrov[disk] = create_inf_dvro()))
goto error;
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PDVRO))) {
/* We point to the right functions */
rpm -> inf_dvrov[disk] -> pr = &pr_dvro_pas;
}
else {
/* If we fit with an inner flat part */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PZDRO))) {
rpm -> inf_dvrov[disk] -> pr = &pr_dvro_act;
}
else {
rpm -> inf_dvrov[disk] -> pr = &pr_dvro_act2;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_dvro(rpm -> inf_dvrov[disk]);
rpm -> inf_dvrov[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm0 struct */
static int chkb_dvra(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the vrad struct */
if (!(rpm -> inf_dvrav[disk]))
if (!(rpm -> inf_dvrav[disk] = create_inf_dvra()))
goto error;
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PDVRA))) {
/* We point to the right functions */
rpm -> inf_dvrav[disk] -> pr = &pr_dvra_pas;
}
else {
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PZDRA))) {
/* We point to the right functions */
rpm -> inf_dvrav[disk] -> pr = &pr_dvra_act;
}
else {
rpm -> inf_dvrav[disk] -> pr = &pr_dvra_act2;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_dvra(rpm -> inf_dvrav[disk]);
rpm -> inf_dvrav[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm0 struct */
static int chkb_dvve(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the vrad struct */
if (!(rpm -> inf_dvvev[disk]))
if (!(rpm -> inf_dvvev[disk] = create_inf_dvve()))
goto error;
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PDVVE))) {
/* We point to the right functions */
rpm -> inf_dvvev[disk] -> pr = &pr_dvve_pas;
}
else {
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PZDVE))) {
/* We point to the right functions */
rpm -> inf_dvvev[disk] -> pr = &pr_dvve_act;
}
else {
rpm -> inf_dvvev[disk] -> pr = &pr_dvve_act2;
}
/* allocate the vver struct*/
chkb_vver((void *) rpm, fit);
/* Ensure that the right type of rotation takes place ERROR SOURCE?*/
rpm -> inf_vverv[disk] -> pr_rota = &pr_vver_rota_act;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_dvve(rpm -> inf_dvvev[disk]);
rpm -> inf_dvvev[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm0 struct */
static int chkb_vm0(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the vm0 struct */
if (!(rpm -> inf_vm0v[disk]))
if (!(rpm -> inf_vm0v[disk] = create_inf_vm0()))
goto error;
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM0A))) {
/* We point to the right functions */
rpm -> inf_vm0v[disk] -> pr = &pr_vmi_pas;
}
else {
/* We point to the right functions */
rpm -> inf_vm0v[disk] -> pr = &pr_vm0_act;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_vm0(rpm -> inf_vm0v[disk]);
rpm -> inf_vm0v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm1 struct */
static int chkb_vm1(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_vm1v[disk]))
if (!(rpm -> inf_vm1v[disk] = create_inf_vm1()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM1A))) {
rpm -> inf_vm1v[disk] -> prs = rpm -> inf_vm1v[disk] -> prc = &pr_vmi_pas;
rpm -> inf_vm1v[disk] -> srprs = rpm -> inf_vm1v[disk] -> srprc = &srpr_vmi_pas;
}
else {
rpm -> inf_vm1v[disk] -> prs = &pr_vm1s_act;
rpm -> inf_vm1v[disk] -> prc = &pr_vm1c_act;
rpm -> inf_vm1v[disk] -> srprs = &srpr_vm1s_act;
rpm -> inf_vm1v[disk] -> srprc = &srpr_vm1c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM1P))) {
rpm -> inf_vm1v[disk] -> prs = &pr_vmi_pas;
rpm -> inf_vm1v[disk] -> srprs = &srpr_vmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM1P, PIHALF))) {
rpm -> inf_vm1v[disk] -> prc = &pr_vmi_pas;
rpm -> inf_vm1v[disk] -> srprc = &srpr_vmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_vm1(rpm -> inf_vm1v[disk]);
rpm -> inf_vm1v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm2 struct */
static int chkb_vm2(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_vm2v[disk]))
if (!(rpm -> inf_vm2v[disk] = create_inf_vm2()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM2A))) {
rpm -> inf_vm2v[disk] -> prs = rpm -> inf_vm2v[disk] -> prc = &pr_vmi_pas;
rpm -> inf_vm2v[disk] -> srprs = rpm -> inf_vm2v[disk] -> srprc = &srpr_vmi_pas;
}
else {
rpm -> inf_vm2v[disk] -> prs = &pr_vm2s_act;
rpm -> inf_vm2v[disk] -> prc = &pr_vm2c_act;
rpm -> inf_vm2v[disk] -> srprs = &srpr_vm2s_act;
rpm -> inf_vm2v[disk] -> srprc = &srpr_vm2c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM2P))) {
rpm -> inf_vm2v[disk] -> prs = &pr_vmi_pas;
rpm -> inf_vm2v[disk] -> srprs = &srpr_vmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM2P, PIHALF))) {
rpm -> inf_vm2v[disk] -> prs = &pr_vmi_pas;
rpm -> inf_vm2v[disk] -> srprs = &srpr_vmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_vm2(rpm -> inf_vm2v[disk]);
rpm -> inf_vm2v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm3 struct */
static int chkb_vm3(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_vm3v[disk]))
if (!(rpm -> inf_vm3v[disk] = create_inf_vm3()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM3A))) {
rpm -> inf_vm3v[disk] -> prs = rpm -> inf_vm3v[disk] -> prc = &pr_vmi_pas;
rpm -> inf_vm3v[disk] -> srprs = rpm -> inf_vm3v[disk] -> srprc = &srpr_vmi_pas;
}
else {
rpm -> inf_vm3v[disk] -> prs = &pr_vm3s_act;
rpm -> inf_vm3v[disk] -> prc = &pr_vm3c_act;
rpm -> inf_vm3v[disk] -> srprs = &srpr_vm3s_act;
rpm -> inf_vm3v[disk] -> srprc = &srpr_vm3c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM3P))) {
rpm -> inf_vm3v[disk] -> prs = &pr_vmi_pas;
rpm -> inf_vm3v[disk] -> srprs = &srpr_vmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM3P, PIHALF))) {
rpm -> inf_vm3v[disk] -> prc = &pr_vmi_pas;
rpm -> inf_vm3v[disk] -> srprc = &srpr_vmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_vm3(rpm -> inf_vm3v[disk]);
rpm -> inf_vm3v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the vm4 struct */
static int chkb_vm4(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_vm4v[disk]))
if (!(rpm -> inf_vm4v[disk] = create_inf_vm4()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM4A))) {
rpm -> inf_vm4v[disk] -> prs = rpm -> inf_vm4v[disk] -> prc = &pr_vmi_pas;
rpm -> inf_vm4v[disk] -> srprs = rpm -> inf_vm4v[disk] -> srprc = &srpr_vmi_pas;
}
else {
rpm -> inf_vm4v[disk] -> prs = &pr_vm4s_act;
rpm -> inf_vm4v[disk] -> prc = &pr_vm4c_act;
rpm -> inf_vm4v[disk] -> srprs = &srpr_vm4s_act;
rpm -> inf_vm4v[disk] -> srprc = &srpr_vm4c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM4P))) {
rpm -> inf_vm4v[disk] -> prs = &pr_vmi_pas;
rpm -> inf_vm4v[disk] -> srprs = &srpr_vmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PVM4P, PIHALF))) {
rpm -> inf_vm4v[disk] -> prs = &pr_vmi_pas;
rpm -> inf_vm4v[disk] -> srprs = &srpr_vmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_vm4(rpm -> inf_vm4v[disk]);
rpm -> inf_vm4v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ra1 struct */
static int chkb_ra1(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ra1v[disk]))
if (!(rpm -> inf_ra1v[disk] = create_inf_ra1()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA1A))) {
rpm -> inf_ra1v[disk] -> prs = rpm -> inf_ra1v[disk] -> prc = &pr_rai_pas;
rpm -> inf_ra1v[disk] -> srprs = rpm -> inf_ra1v[disk] -> srprc = &srpr_rai_pas;
}
else {
rpm -> inf_ra1v[disk] -> prs = &pr_ra1s_act;
rpm -> inf_ra1v[disk] -> prc = &pr_ra1c_act;
rpm -> inf_ra1v[disk] -> srprs = &srpr_ra1s_act;
rpm -> inf_ra1v[disk] -> srprc = &srpr_ra1c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA1P))) {
rpm -> inf_ra1v[disk] -> prs = &pr_rai_pas;
rpm -> inf_ra1v[disk] -> srprs = &srpr_rai_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA1P, PIHALF))) {
rpm -> inf_ra1v[disk] -> prc = &pr_rai_pas;
rpm -> inf_ra1v[disk] -> srprc = &srpr_rai_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ra1(rpm -> inf_ra1v[disk]);
rpm -> inf_ra1v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ra2 struct */
static int chkb_ra2(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ra2v[disk]))
if (!(rpm -> inf_ra2v[disk] = create_inf_ra2()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA2A))) {
rpm -> inf_ra2v[disk] -> prs = rpm -> inf_ra2v[disk] -> prc = &pr_rai_pas;
rpm -> inf_ra2v[disk] -> srprs = rpm -> inf_ra2v[disk] -> srprc = &srpr_rai_pas;
}
else {
rpm -> inf_ra2v[disk] -> prs = &pr_ra2s_act;
rpm -> inf_ra2v[disk] -> prc = &pr_ra2c_act;
rpm -> inf_ra2v[disk] -> srprs = &srpr_ra2s_act;
rpm -> inf_ra2v[disk] -> srprc = &srpr_ra2c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA2P))) {
rpm -> inf_ra2v[disk] -> prs = &pr_rai_pas;
rpm -> inf_ra2v[disk] -> srprs = &srpr_rai_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA2P, PIHALF))) {
rpm -> inf_ra2v[disk] -> prs = &pr_rai_pas;
rpm -> inf_ra2v[disk] -> srprs = &srpr_rai_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ra2(rpm -> inf_ra2v[disk]);
rpm -> inf_ra2v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ra3 struct */
static int chkb_ra3(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ra3v[disk]))
if (!(rpm -> inf_ra3v[disk] = create_inf_ra3()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA3A))) {
rpm -> inf_ra3v[disk] -> prs = rpm -> inf_ra3v[disk] -> prc = &pr_rai_pas;
rpm -> inf_ra3v[disk] -> srprs = rpm -> inf_ra3v[disk] -> srprc = &srpr_rai_pas;
}
else {
rpm -> inf_ra3v[disk] -> prs = &pr_ra3s_act;
rpm -> inf_ra3v[disk] -> prc = &pr_ra3c_act;
rpm -> inf_ra3v[disk] -> srprs = &srpr_ra3s_act;
rpm -> inf_ra3v[disk] -> srprc = &srpr_ra3c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA3P))) {
rpm -> inf_ra3v[disk] -> prs = &pr_rai_pas;
rpm -> inf_ra3v[disk] -> srprs = &srpr_rai_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA3P, PIHALF))) {
rpm -> inf_ra3v[disk] -> prc = &pr_rai_pas;
rpm -> inf_ra3v[disk] -> srprc = &srpr_rai_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ra3(rpm -> inf_ra3v[disk]);
rpm -> inf_ra3v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ra4 struct */
static int chkb_ra4(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ra4v[disk]))
if (!(rpm -> inf_ra4v[disk] = create_inf_ra4()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA4A))) {
rpm -> inf_ra4v[disk] -> prs = rpm -> inf_ra4v[disk] -> prc = &pr_rai_pas;
rpm -> inf_ra4v[disk] -> srprs = rpm -> inf_ra4v[disk] -> srprc = &srpr_rai_pas;
}
else {
rpm -> inf_ra4v[disk] -> prs = &pr_ra4s_act;
rpm -> inf_ra4v[disk] -> prc = &pr_ra4c_act;
rpm -> inf_ra4v[disk] -> srprs = &srpr_ra4s_act;
rpm -> inf_ra4v[disk] -> srprc = &srpr_ra4c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA4P))) {
rpm -> inf_ra4v[disk] -> prs = &pr_rai_pas;
rpm -> inf_ra4v[disk] -> srprs = &srpr_rai_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRA4P, PIHALF))) {
rpm -> inf_ra4v[disk] -> prs = &pr_rai_pas;
rpm -> inf_ra4v[disk] -> srprs = &srpr_rai_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ra4(rpm -> inf_ra4v[disk]);
rpm -> inf_ra4v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ro1 struct */
static int chkb_ro1(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ro1v[disk]))
if (!(rpm -> inf_ro1v[disk] = create_inf_ro1()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO1A))) {
rpm -> inf_ro1v[disk] -> prs = rpm -> inf_ro1v[disk] -> prc = &pr_roi_pas;
rpm -> inf_ro1v[disk] -> srprs = rpm -> inf_ro1v[disk] -> srprc = &srpr_roi_pas;
}
else {
rpm -> inf_ro1v[disk] -> prs = &pr_ro1s_act;
rpm -> inf_ro1v[disk] -> prc = &pr_ro1c_act;
rpm -> inf_ro1v[disk] -> srprs = &srpr_ro1s_act;
rpm -> inf_ro1v[disk] -> srprc = &srpr_ro1c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO1P))) {
rpm -> inf_ro1v[disk] -> prs = &pr_roi_pas;
rpm -> inf_ro1v[disk] -> srprs = &srpr_roi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO1P, PIHALF))) {
rpm -> inf_ro1v[disk] -> prc = &pr_roi_pas;
rpm -> inf_ro1v[disk] -> srprc = &srpr_roi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ro1(rpm -> inf_ro1v[disk]);
rpm -> inf_ro1v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ro2 struct */
static int chkb_ro2(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ro2v[disk]))
if (!(rpm -> inf_ro2v[disk] = create_inf_ro2()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO2A))) {
rpm -> inf_ro2v[disk] -> prs = rpm -> inf_ro2v[disk] -> prc = &pr_roi_pas;
rpm -> inf_ro2v[disk] -> srprs = rpm -> inf_ro2v[disk] -> srprc = &srpr_roi_pas;
}
else {
rpm -> inf_ro2v[disk] -> prs = &pr_ro2s_act;
rpm -> inf_ro2v[disk] -> prc = &pr_ro2c_act;
rpm -> inf_ro2v[disk] -> srprs = &srpr_ro2s_act;
rpm -> inf_ro2v[disk] -> srprc = &srpr_ro2c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO2P))) {
rpm -> inf_ro2v[disk] -> prs = &pr_roi_pas;
rpm -> inf_ro2v[disk] -> srprs = &srpr_roi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO2P, PIHALF))) {
rpm -> inf_ro2v[disk] -> prs = &pr_roi_pas;
rpm -> inf_ro2v[disk] -> srprs = &srpr_roi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ro2(rpm -> inf_ro2v[disk]);
rpm -> inf_ro2v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ro3 struct */
static int chkb_ro3(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ro3v[disk]))
if (!(rpm -> inf_ro3v[disk] = create_inf_ro3()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO3A))) {
rpm -> inf_ro3v[disk] -> prs = rpm -> inf_ro3v[disk] -> prc = &pr_roi_pas;
rpm -> inf_ro3v[disk] -> srprs = rpm -> inf_ro3v[disk] -> srprc = &srpr_roi_pas;
}
else {
rpm -> inf_ro3v[disk] -> prs = &pr_ro3s_act;
rpm -> inf_ro3v[disk] -> prc = &pr_ro3c_act;
rpm -> inf_ro3v[disk] -> srprs = &srpr_ro3s_act;
rpm -> inf_ro3v[disk] -> srprc = &srpr_ro3c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO3P))) {
rpm -> inf_ro3v[disk] -> prs = &pr_roi_pas;
rpm -> inf_ro3v[disk] -> srprs = &srpr_roi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO3P, PIHALF))) {
rpm -> inf_ro3v[disk] -> prc = &pr_roi_pas;
rpm -> inf_ro3v[disk] -> srprc = &srpr_roi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ro3(rpm -> inf_ro3v[disk]);
rpm -> inf_ro3v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ro4 struct */
static int chkb_ro4(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ro4v[disk]))
if (!(rpm -> inf_ro4v[disk] = create_inf_ro4()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO4A))) {
rpm -> inf_ro4v[disk] -> prs = rpm -> inf_ro4v[disk] -> prc = &pr_roi_pas;
rpm -> inf_ro4v[disk] -> srprs = rpm -> inf_ro4v[disk] -> srprc = &srpr_roi_pas;
}
else {
rpm -> inf_ro4v[disk] -> prs = &pr_ro4s_act;
rpm -> inf_ro4v[disk] -> prc = &pr_ro4c_act;
rpm -> inf_ro4v[disk] -> srprs = &srpr_ro4s_act;
rpm -> inf_ro4v[disk] -> srprc = &srpr_ro4c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO4P))) {
rpm -> inf_ro4v[disk] -> prs = &pr_roi_pas;
rpm -> inf_ro4v[disk] -> srprs = &srpr_roi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PRO4P, PIHALF))) {
rpm -> inf_ro4v[disk] -> prs = &pr_roi_pas;
rpm -> inf_ro4v[disk] -> srprs = &srpr_roi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ro4(rpm -> inf_ro4v[disk]);
rpm -> inf_ro4v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the wm0 struct */
static int chkb_wm0(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
/* We allocate the wm0 struct */
if (!(rpm -> inf_wm0v[disk]))
if (!(rpm -> inf_wm0v[disk] = create_inf_wm0()))
goto error;
/* If we fit ... */
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM0A))) {
/* We point to the right functions */
rpm -> inf_wm0v[disk] -> pr = &pr_wmi_pas;
}
else {
/* We point to the right functions */
rpm -> inf_wm0v[disk] -> pr = &pr_wm0_act;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_wm0(rpm -> inf_wm0v[disk]);
rpm -> inf_wm0v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the wm1 struct */
static int chkb_wm1(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_wm1v[disk]))
if (!(rpm -> inf_wm1v[disk] = create_inf_wm1()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM1A))) {
rpm -> inf_wm1v[disk] -> prs = rpm -> inf_wm1v[disk] -> prc = &pr_wmi_pas;
rpm -> inf_wm1v[disk] -> srprs = rpm -> inf_wm1v[disk] -> srprc = &srpr_wmi_pas;
}
else {
rpm -> inf_wm1v[disk] -> prs = &pr_wm1s_act;
rpm -> inf_wm1v[disk] -> prc = &pr_wm1c_act;
rpm -> inf_wm1v[disk] -> srprs = &srpr_wm1s_act;
rpm -> inf_wm1v[disk] -> srprc = &srpr_wm1c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM1P))) {
rpm -> inf_wm1v[disk] -> prs = &pr_wmi_pas;
rpm -> inf_wm1v[disk] -> srprs = &srpr_wmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM1P, PIHALF))) {
rpm -> inf_wm1v[disk] -> prc = &pr_wmi_pas;
rpm -> inf_wm1v[disk] -> srprc = &srpr_wmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_wm1(rpm -> inf_wm1v[disk]);
rpm -> inf_wm1v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the wm2 struct */
static int chkb_wm2(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_wm2v[disk]))
if (!(rpm -> inf_wm2v[disk] = create_inf_wm2()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM2A))) {
rpm -> inf_wm2v[disk] -> prs = rpm -> inf_wm2v[disk] -> prc = &pr_wmi_pas;
rpm -> inf_wm2v[disk] -> srprs = rpm -> inf_wm2v[disk] -> srprc = &srpr_wmi_pas;
}
else {
rpm -> inf_wm2v[disk] -> prs = &pr_wm2s_act;
rpm -> inf_wm2v[disk] -> prc = &pr_wm2c_act;
rpm -> inf_wm2v[disk] -> srprs = &srpr_wm2s_act;
rpm -> inf_wm2v[disk] -> srprc = &srpr_wm2c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM2P))) {
rpm -> inf_wm2v[disk] -> prs = &pr_wmi_pas;
rpm -> inf_wm2v[disk] -> srprs = &srpr_wmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM2P, PIHALF))) {
rpm -> inf_wm2v[disk] -> prs = &pr_wmi_pas;
rpm -> inf_wm2v[disk] -> srprs = &srpr_wmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_wm2(rpm -> inf_wm2v[disk]);
rpm -> inf_wm2v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the wm3 struct */
static int chkb_wm3(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_wm3v[disk]))
if (!(rpm -> inf_wm3v[disk] = create_inf_wm3()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM3A))) {
rpm -> inf_wm3v[disk] -> prs = rpm -> inf_wm3v[disk] -> prc = &pr_wmi_pas;
rpm -> inf_wm3v[disk] -> srprs = rpm -> inf_wm3v[disk] -> srprc = &srpr_wmi_pas;
}
else {
rpm -> inf_wm3v[disk] -> prs = &pr_wm3s_act;
rpm -> inf_wm3v[disk] -> prc = &pr_wm3c_act;
rpm -> inf_wm3v[disk] -> srprs = &srpr_wm3s_act;
rpm -> inf_wm3v[disk] -> srprc = &srpr_wm3c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM3P))) {
rpm -> inf_wm3v[disk] -> prs = &pr_wmi_pas;
rpm -> inf_wm3v[disk] -> srprs = &srpr_wmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM3P, PIHALF))) {
rpm -> inf_wm3v[disk] -> prc = &pr_wmi_pas;
rpm -> inf_wm3v[disk] -> srprc = &srpr_wmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_wm3(rpm -> inf_wm3v[disk]);
rpm -> inf_wm3v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the wm4 struct */
static int chkb_wm4(ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_wm4v[disk]))
if (!(rpm -> inf_wm4v[disk] = create_inf_wm4()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM4A))) {
rpm -> inf_wm4v[disk] -> prs = rpm -> inf_wm4v[disk] -> prc = &pr_wmi_pas;
rpm -> inf_wm4v[disk] -> srprs = rpm -> inf_wm4v[disk] -> srprc = &srpr_wmi_pas;
}
else {
rpm -> inf_wm4v[disk] -> prs = &pr_wm4s_act;
rpm -> inf_wm4v[disk] -> prc = &pr_wm4c_act;
rpm -> inf_wm4v[disk] -> srprs = &srpr_wm4s_act;
rpm -> inf_wm4v[disk] -> srprc = &srpr_wm4c_act;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM4P))) {
rpm -> inf_wm4v[disk] -> prs = &pr_wmi_pas;
rpm -> inf_wm4v[disk] -> srprs = &srpr_wmi_pas;
}
else if ((chkb_val(rpm, fit, PRPARAMS+disk*NDPARAMS+PWM4P, PIHALF))) {
rpm -> inf_wm4v[disk] -> prs = &pr_wmi_pas;
rpm -> inf_wm4v[disk] -> srprs = &srpr_wmi_pas;
}
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_wm4(rpm -> inf_wm4v[disk]);
rpm -> inf_wm4v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the ls0 struct */
static int chkb_ls0 (ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_ls0v[disk]))
if (!(rpm -> inf_ls0v[disk] = create_inf_ls0 ()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PLS0 ))) {
rpm -> inf_ls0v[disk] -> pr = &pr_ls0_pas;
}
else {
rpm -> inf_ls0v[disk] -> pr = &pr_ls0_act;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_ls0(rpm -> inf_ls0v[disk]);
rpm -> inf_ls0v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Optionally allocates and puts correct switches in the lc0 struct */
static int chkb_lc0 (ringparms *rpm, fitparms *fit)
{
int disk;
for (disk = 0; disk < rpm -> ndisks; ++ disk) {
if (!(rpm -> inf_lc0v[disk]))
if (!(rpm -> inf_lc0v[disk] = create_inf_lc0 ()))
goto error;
if ((chkb_zero(rpm, fit, PRPARAMS+disk*NDPARAMS+PLC0 ))) {
rpm -> inf_lc0v[disk] -> pr = &pr_lc0_pas;
}
else {
rpm -> inf_lc0v[disk] -> pr = &pr_lc0_act;
}
}
return 0;
error:
for (disk = 0; disk < rpm -> ndisks; ++disk) {
destroy_inf_lc0(rpm -> inf_lc0v[disk]);
rpm -> inf_lc0v[disk] = NULL;
}
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* check if the function should be activated */
static int chkb_zero(ringparms *rpm, fitparms *fit, int ident)
{
return chkb_val(rpm, fit, ident, 0.0);
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* check if the function should be activated */
static int chkb_val(ringparms *rpm, fitparms *fit, int ident, double val)
{
int i, yesno = 1;
varlel *varele;
/* We check if this is unequal zero in the input */
for (i=0; i < rpm -> nur; ++i) {
if (rpm -> par[ident*rpm -> nur+i] != val) {
yesno = 0;
break;
}
}
/* We check if this is fitted going through all the elements */
varele = fit -> varylist;
while ((varele)) {
for (i = 0; i < varele -> nelem; ++i) {
if (varele -> elements[i]/rpm -> nur == ident)
yesno = 0;
}
varele = varele -> next;
}
return yesno;
}
/* ------------------------------------------------------------ */
/*************/
/* Addendums under construction */
/*************/
/* #include "constr.c" */
/*************/
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Constructs a NULL-terminated array of n (empty) reg_containers */
static reg_cont **reg_cont_const(int nregs)
{
reg_cont **reg_cont_const = NULL;
int i;
if (nregs < 0)
return NULL;
if (!(reg_cont_const = (reg_cont **) malloc ((nregs+1)*sizeof(reg_cont *))))
return NULL;
for (i = 0; i <= nregs; ++i)
reg_cont_const[i] = NULL;
for (i = 0; i < nregs; ++i) {
if (!(reg_cont_const[i] = (reg_cont *) malloc (sizeof(reg_cont)))) {
reg_cont_destr(reg_cont_const);
return NULL;
}
}
for (i = 0; i < nregs; ++i) {
if (!(reg_cont_const[i] -> fc = fourat_container_const())) {
reg_cont_destr(reg_cont_const);
return NULL;
}
}
return reg_cont_const;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Constructs a NULL-terminated array of n (empty) reg_containers */
static int reg_cont_destr(reg_cont **reg_contv)
{
int i = 0;
if (!reg_contv)
return 1;
while ((reg_contv[i])) {
if ((reg_contv[i] -> fc)) {
fourat_container_destr(reg_contv[i] -> fc);
}
free(reg_contv[i]);
++i;
}
free(reg_contv);
return 0;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Get the regularisation list from user input */
static reg_cont **reg_cont_get(startinf *startinfv, hdrinf *hdr, ringparms *rpm, fitparms *fit)
{
reg_cont **reg_cont_get = NULL;
/**************/
/**************/
/* int obsint = 0; */
/* char obsmes[200]; */
/* double *obsdouble; */
/**************/
/* Simple control stuff */
int nel, def, i, j, k;
char mes[81]; /* Any message */
int errcode = 1, outside = 0; /* another error code */
char *varyhstr= NULL;
char **varystr = NULL;
char *dummystr = NULL;
decomp_control decomp_controlv = NULL;
decomp_listel *decomp_listelvact = NULL;
decomp_listel *decomp_listelvden = NULL;
decomp_listel *decomp_listelvnum = NULL;
decomp_listel *decomp_listelvdum = NULL;
char *dcperr;
int par = 0;
int maxorder;
int nregs;
int anint;
double *regthre = NULL, *regwidt = NULL, *regampl = NULL, *regaste = NULL, *regampd = NULL;
int nreadl, nreturned, keypres;
/* The complicated varystr */
/* if (!(varystr = (char **) malloc(VARYSTRELES*sizeof(char *)))) */
/* goto error; */
/* if (!(varyhstr = getfcharray(VARYHSTRELES, NULL))) */
/* goto error; */
/* get the dcp control structure */
if (!(decomp_controlv = decomp_init()))
goto error;
/* Fill the dcp control structure with parameter information */
if ((dec_fill(rpm, decomp_controlv)))
goto error;
/* First we fetch the list of parameters that should be regulated */
errcode = 1;
/* Get the array */
while (errcode) {
nel = 0;
def = 1;
if (errcode == 2)
cancel_tir(startinfv -> arel, "REGPARA=", 2);
/* sprintf(mes, "Give parameters to regularise"); */
/* flushfcharray(VARYHSTRELES, varyhstr); */
/* nel = usertext_tir(varyhstr, &def, "REGPARA=", mes); */
if ((varyhstr)) {
free(varyhstr);
varyhstr = NULL;
}
if (simparse_scn_arel_readval_string(startinfv -> arel, "REGPARA", "Give parameters to regularise.", 0, "", 0, -1, 0, 0, &keypres, &nreadl, &nreturned, &varyhstr))
goto error;
/* Interlude: Change the case if it is lower case */
i = 0;
while (varyhstr[i]) {
if (varyhstr[i] >= 'a' && varyhstr[i] <= 'z') {
varyhstr[i] = varyhstr[i]+'A'-'a';
}
++i;
}
decomp_putsep(decomp_controlv, ',', '\0', ':');
if ((decomp_listelvact))
decomp_list_dest(decomp_listelvact);
decomp_listelvact = NULL;
/* Interpret this */
if ((errcode = decomp_get(decomp_controlv, varyhstr, &decomp_listelvact, 0))){
if (errcode == 1)
goto error;
else {
sprintf(mes, "REGPARA: ");
if ((dcperr = decomp_errmsg(decomp_controlv)))
strncpy(mes+9, dcperr, 71);
anyout_tir(&def, mes);
}
}
/* Now do a sanity check: no group is allowed to point to intrinsically different elements */
outside = 0;
if (decomp_listelvact) {
i = 0;
nregs = 0;
while ((decomp_listelvact+i) -> nuel != -1) {
++nregs;
if (((decomp_listelvact+i) -> nuel)) {
par = (decomp_listelvact+i) -> poli[0] / rpm -> nur;
}
for (j = 0; j < (decomp_listelvact+i) -> nuel; ++j){
if (par != (decomp_listelvact+i) -> poli[j] / rpm -> nur) {
outside = 1;
}
par = (decomp_listelvact+i) -> poli[j] / rpm -> nur;
}
++i;
}
}
else {
nregs = 0;
}
if ((outside)) {
sprintf(mes,"REGPARA: one parameter only between commas.");
anyout_tir(&def, mes);
errcode |= 2;
}
}
/* Provide an array of reg_conts */
if (!(reg_cont_get = reg_cont_const(nregs)))
goto error;
/* proceed if there is more than 0 elements */
if ((nregs)) {
/* Now read in the lists */
/* calculate the maximum order */
maxorder = rpm -> nur/2;
/* Read in an array of arrays from den */
/* Reallocate the thingy */
decomp_dest(decomp_controlv);
if (!(decomp_controlv = decomp_init()))
goto error;
/* Feed it with exactly one thing */
/* if ((decomp_inp(decomp_controlv, "D", 0, maxorder))) */
if ((decomp_inp(decomp_controlv, "D", 1, maxorder)))
goto error;
decomp_putsep(decomp_controlv, '\0', '\0', ':');
errcode = 3;
def = 1;
while (errcode) {
if (errcode != 3)
cancel_tir(startinfv -> arel, "REGDENO=", 2);
errcode = 0;
sprintf(mes, "Enter denominator");
/* flushfcharray(VARYHSTRELES, varyhstr); */
/* nel = usertext_tir(varyhstr, &def, "REGDENO=", mes); */
if ((varyhstr)) {
free(varyhstr);
varyhstr = NULL;
}
if (simparse_scn_arel_readval_string(startinfv -> arel, "REGDENO", mes, 0, "", 0, -1, 0, 0, &keypres, &nreadl, &nreturned, &varyhstr))
goto error;
/* Is this empty? */
if ((varystr)) {
freeparsed(varystr);
/* i = 0; */
/* while(varystr[i]) { */
/* free(varystr[i]); */
/* ++i; */
/* } */
/* free(varystr); */
varystr = NULL;
}
if (!(varystr = sparsenext(",", "", "\t", "", "", "", -1, &varyhstr, &anint, 0, 1))) {
sprintf(mes,"Please enter sufficient parameters for REGDENO.");
anyout_tir(&def, mes);
errcode = 1;
}
else {
/* It has to have exactly nreg elements, and determine the maximum length of the arrays */
i = 0;
j = 0;
while ((varystr[i])) {
if ((k = strlen(varystr[i])) > j) {
j = k;
}
++i;
}
if (i != nregs) {
sprintf(mes,"Please enter sufficient parameters for REGDENO.");
anyout_tir(&def, mes);
errcode = 1;
}
else {
if (!(decomp_listelvden = (decomp_listel *) malloc((nregs+1)*sizeof(decomp_listel))))
goto error;
/* Now read in the single arrays for regd */
if ((dummystr)) {
free(dummystr);
dummystr = NULL;
}
if (!(dummystr = (char *) malloc((j+3)*sizeof(char))))
goto error;
for (i = 0; i < nregs; ++i) {
sprintf(dummystr,"D ");
sprintf(dummystr+2,"%s",varystr[i]);
if ((decomp_listelvdum)) {
free(decomp_listelvdum);
decomp_listelvdum = NULL;
}
if ((errcode = decomp_get(decomp_controlv, dummystr, &decomp_listelvdum, 1))){
if (errcode == 1)
goto error;
else {
sprintf(mes, "REGDENO: ");
if ((dcperr = decomp_errmsg(decomp_controlv)))
strncpy(mes+9, dcperr, 71);
anyout_tir(&def, mes);
}
}
if (decomp_listelvdum) {
if (decomp_listelvdum -> nuel < 1) {
sprintf(mes,"Enter sufficient parameters for REGDENO.");
anyout_tir(&def, mes);
errcode = 1;
}
else {
for (k = 0; k < decomp_listelvdum -> nuel; ++k) {
if ((decomp_listelvdum -> poli[k] < 0) || (decomp_listelvdum -> poli[k] > maxorder)) {
errcode = 1;
break;
}
}
if (errcode == 1) {
sprintf(mes,"Order is between %i and %i", 0, maxorder);
anyout_tir(&def, mes);
}
}
}
if ((errcode)) {
break;
}
(decomp_listelvden+i) -> nuel = decomp_listelvdum -> nuel;
(decomp_listelvden+i) -> poli = decomp_listelvdum -> poli;
}
while (i < nregs) {
(decomp_listelvden+i) -> nuel = 0;
(decomp_listelvden+i) -> poli = NULL;
++i;
}
(decomp_listelvden+nregs) -> nuel = -1;
(decomp_listelvden+nregs) -> poli = NULL;
}
}
}
errcode = 3;
while (errcode) {
if (errcode != 3)
cancel_tir(startinfv -> arel, "REGNUME=", 2);
errcode = 0;
/* flushfcharray(VARYHSTRELES, varyhstr); */
/* nel = usertext_tir(varyhstr, &def, "REGNUME=", mes); */
if ((varyhstr)) {
free(varyhstr);
varyhstr = NULL;
}
sprintf(mes,"Please enter sufficient parameters for REGNUME.");
if (simparse_scn_arel_readval_string(startinfv -> arel, "REGNUME", mes, 0, "", 0, -1, 0, 0, &keypres, &nreadl, &nreturned, &varyhstr))
goto error;
/* Is this empty? */
if ((varystr)) {
freeparsed(varystr);
/* i = 0; */
/* while(varystr[i]) { */
/* free(varystr[i]); */
/* ++i; */
/* } */
/* free(varystr); */
varystr = NULL;
}
if (!(varystr = sparsenext(",", "", "\t", "", "", "", -1, &varyhstr, &anint, 0, 1))) {
sprintf(mes,"Please enter sufficient parameters for REGNUME.");
anyout_tir(&def, mes);
errcode = 1;
}
else {
/* It has to have exactly nreg elements, and determine the maximum length of the arrays */
i = 0;
j = 0;
while ((varystr[i])) {
if ((k = strlen(varystr[i])) > j) {
j = k;
}
++i;
}
if (i != nregs) {
sprintf(mes,"Please enter sufficient parameters for REGNUME.");
anyout_tir(&def, mes);
errcode = 1;
}
else {
if (!(decomp_listelvnum = (decomp_listel *) malloc((nregs+1)*sizeof(decomp_listel))))
goto error;
/* Now read in the single arrays for regd */
if ((dummystr)) {
free(dummystr);
dummystr = NULL;
}
if (!(dummystr = (char *) malloc((j+3)*sizeof(char))))
goto error;
for (i = 0; i < nregs; ++i) {
sprintf(dummystr,"D ");
sprintf(dummystr+2,"%s",varystr[i]);
if ((decomp_listelvdum)) {
free(decomp_listelvdum);
decomp_listelvdum = NULL;
}
if ((errcode = decomp_get(decomp_controlv, dummystr, &decomp_listelvdum, 1))){
if (errcode == 1)
goto error;
else {
sprintf(mes, "REGNUME: ");
if ((dcperr = decomp_errmsg(decomp_controlv)))
strncpy(mes+9, dcperr, 71);
anyout_tir(&def, mes);
}
}
if (decomp_listelvdum) {
if (decomp_listelvdum -> nuel < 1) {
sprintf(mes,"Please enter sufficient parameters for REGNUME.");
anyout_tir(&def, mes);
errcode = 1;
}
else {
for (k = 0; k < decomp_listelvdum -> nuel; ++k) {
if ((decomp_listelvdum -> poli[k] < 0) || (decomp_listelvdum -> poli[k] > maxorder)) {
errcode = 1;
break;
}
}
if (errcode == 1) {
sprintf(mes,"Order is between %i and %i", 0, maxorder);
anyout_tir(&def, mes);
}
}
}
if ((errcode)) {
break;
}
(decomp_listelvnum+i) -> nuel = decomp_listelvdum -> nuel;
(decomp_listelvnum+i) -> poli = decomp_listelvdum -> poli;
}
while (i < nregs) {
(decomp_listelvnum+i) -> nuel = 0;
(decomp_listelvnum+i) -> poli = NULL;
++i;
}
(decomp_listelvnum+nregs) -> nuel = -1;
(decomp_listelvnum+nregs) -> poli = NULL;
}
}
}
/* Allocate and read in the three additional quantities */
if (!(regthre = (double *) malloc(nregs*sizeof(double))))
goto error;
if (!(regwidt = (double *) malloc(nregs*sizeof(double))))
goto error;
if (!(regampl = (double *) malloc(nregs*sizeof(double))))
goto error;
if (!(regaste = (double *) malloc(nregs*sizeof(double))))
goto error;
if (!(regampd = (double *) malloc(nregs*sizeof(double))))
goto error;
def = 0;
/* Get the regthre */
errcode = 1;
sprintf(mes, "Give ratio threshold (in the same order)");
while (errcode) {
errcode = 0;
nel = userdble_tir(startinfv -> arel, regthre, &nregs, &def, "REGTHRE=", mes);
if (!nel) {
sprintf(mes, "Something went wrong. Give REGTHRE=");
cancel_tir(startinfv -> arel, "REGTHRE=", 2);
errcode = 1;
}
while (nel < nregs) {
regthre[nel] = regthre[nel-1];
++nel;
}
}
/* Get the regwidt */
errcode = 1;
sprintf(mes, "Give ratio step width (in the same order)");
while (errcode) {
errcode = 0;
nel = userdble_tir(startinfv -> arel, regwidt, &nregs, &def, "REGWIDT=", mes);
if (!nel) {
sprintf(mes, "Something went wrong. Give REGWIDT=");
cancel_tir(startinfv -> arel, "REGWIDT=", 2);
errcode = 1;
}
while (nel < nregs) {
regwidt[nel] = regwidt[nel-1];
++nel;
}
}
/* Get the regampl */
errcode = 1;
sprintf(mes, "Give parameter step amplitude (in the same order)");
while (errcode) {
errcode = 0;
nel = userdble_tir(startinfv -> arel, regampl, &nregs, &def, "REGAMPL=", mes);
if (!nel) {
sprintf(mes, "Something went wrong. Give REGAMPL=");
cancel_tir(startinfv -> arel, "REGAMPL=", 2);
errcode = 1;
}
while (nel < nregs) {
regampl[nel] = regampl[nel-1];
++nel;
}
}
/* Get the regaste */
errcode = 1;
/* Notice that this is additive; the chisquared of an empty cube is N_x*N_y*N_v */
sprintf(mes, "Give parameter amplitude increase per loop");
while (errcode) {
errcode = 0;
nel = userdble_tir(startinfv -> arel, regaste, &nregs, &def, "REGASTE=", mes);
if (!nel) {
sprintf(mes, "Something went wrong. Give REGASTE=");
cancel_tir(startinfv -> arel, "REGASTE=", 2);
errcode = 1;
}
while (nel < nregs) {
regaste[nel] = regaste[nel-1];
++nel;
}
}
/* Get the regampd */
errcode = 1;
/* Notice that this is additive; the chisquared of an empty cube is N_x*N_y*N_v */
sprintf(mes, "Give absolute denominator (>0)");
while (errcode) {
errcode = 0;
nel = userdble_tir(startinfv -> arel, regampd, &nregs, &def, "REGAMPD=", mes);
if (!nel) {
sprintf(mes, "Something went wrong. Give REGAMPD=");
cancel_tir(startinfv -> arel, "REGAMPD=", 2);
errcode = 1;
}
while (nel < nregs) {
regampd[nel] = regampd[nel-1];
++nel;
}
}
}
/* Now that we have the three arrays of listels, we continue with filling and initialising the fourat structure */
for (i = 0; i < nregs; ++i) {
fourat_put_length(reg_cont_get[i] -> fc, rpm -> nur, (decomp_listelvact+i) -> nuel, (decomp_listelvnum+i) -> nuel, (decomp_listelvden+i) -> nuel, HUGE_DBL);
if (fourat_meminit(reg_cont_get[i] -> fc)) {
goto error;
}
/* Put the position of the first element into the struct */
reg_cont_get[i] -> posoffirst = ((decomp_listelvact+i) -> poli[0]/rpm -> nur)*rpm -> nur;
reg_cont_get[i] -> first = rpm -> par + reg_cont_get[i] -> posoffirst;
/* Recalculate the numbers from the active parameters to the relative positions w.r.t. the first element */
for (j = 0; j < (decomp_listelvact+i) -> nuel; ++j)
(decomp_listelvact+i) -> poli[j] = (decomp_listelvact+i) -> poli[j] % rpm -> nur;
/* Then read in the vectors */
fourat_put_vectors(reg_cont_get[i] -> fc, reg_cont_get[i] -> first, (decomp_listelvact+i) -> poli, (decomp_listelvnum+i) -> poli, (decomp_listelvden+i) -> poli);
/* Initialise again */
fourat_init(reg_cont_get[i] -> fc);
/* clear up the other parameters */
reg_cont_get[i] -> regthre = regthre[i];
reg_cont_get[i] -> regwidt = regwidt[i];
reg_cont_get[i] -> regampl = regampl[i];
reg_cont_get[i] -> regaste = regaste[i];
/* Transfer to intrinsic coordinates and include normalisation */
if (regampd[i] > 0.0){
reg_cont_get[i] -> regampd = ((double) rpm -> nur) * fabs(dparamtointern(regampd[i], reg_cont_get[i] -> posoffirst/rpm -> nur+1, hdr, rpm -> ndisks));
}
else {
reg_cont_get[i] -> regampd = regampd[i];
}
}
if ((varyhstr))
free(varyhstr);
if ((varystr))
freeparsed(varystr);
if ((decomp_controlv))
decomp_dest(decomp_controlv);
if ((decomp_listelvact))
decomp_list_dest(decomp_listelvact);
if ((decomp_listelvden))
decomp_list_dest(decomp_listelvden);
if ((decomp_listelvnum))
decomp_list_dest(decomp_listelvnum);
if ((dummystr))
free(dummystr);
if((regthre))
free(regthre);
if ((regwidt))
free(regwidt);
if ((regampl))
free(regampl);
if ((regaste))
free(regaste);
if ((regampd))
free(regampd);
/**********/
/**********/
/**********/
/* Provide an overview, testing only */
/* sprintf(obsmes,"Testing things"); */
/* anyout_tir(&obsint, obsmes); */
/* if (!(obsdouble = (double *) malloc(rpm -> nur * sizeof(double)))) */
/* goto error; */
/* Count the numbers of regularisation groups */
/* for (nregs = 0; reg_cont_get[nregs]; ++nregs) */
/* ; */
/* Go through the list and read out the input */
/* for (i = 0; i < nregs; ++i) { */
/* sprintf(obsmes, "Group %i, parameter ", i); */
/* what is the name of the first element? */
/* ftstab_putcoltitl(obsmes+strlen(obsmes), reg_cont_get[i] -> posoffirst/rpm -> nur+1); */
/* anyout_tir(&obsint, obsmes); */
/* what are the values (note that this requires hdr, which is not usually passed by the function and has to be included in the input for this test */
/* sprintf(obsmes, "Values: "); */
/* for (j = 0; j < rpm -> nur; ++j) { */
/* sprintf(obsmes+strlen(obsmes), "%.1E ", dinterntoparam(*(reg_cont_get[i] -> first+j), reg_cont_get[i] -> posoffirst/rpm -> nur+1, hdr, rpm -> ndisks)); */
/* } */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Active ringnumbers: "); */
/* for (j = 0; j < reg_cont_get[i] -> fc -> nact; ++j) { */
/* sprintf(obsmes+strlen(obsmes), "%i ", reg_cont_get[i] -> fc -> act[j]); */
/* } */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Orders numerator: "); */
/* for (j = 0; j < reg_cont_get[i] -> fc -> nnum; ++j) { */
/* sprintf(obsmes+strlen(obsmes), "%i ", reg_cont_get[i] -> fc -> num[j]); */
/* } */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Orders denominator: "); */
/* for (j = 0; j < reg_cont_get[i] -> fc -> nden; ++j) { */
/* sprintf(obsmes+strlen(obsmes), "%i ", reg_cont_get[i] -> fc -> den[j]); */
/* } */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Huge value: %.1E %.1E", reg_cont_get[i] -> fc -> huge_dbl, HUGE_DBL); */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Regthre: %.1E", reg_cont_get[i] -> regthre); */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Regwidt: %.1E", reg_cont_get[i] -> regwidt); */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Regampl: %.1E", reg_cont_get[i] -> regampl); */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Regaste: %.1E", reg_cont_get[i] -> regaste); */
/* anyout_tir(&obsint, obsmes); */
/* sprintf(obsmes, "Regampd: %.1E", reg_cont_get[i] -> regampd); */
/* anyout_tir(&obsint, obsmes); */
/* Usage of smoothstep */
/* sprintf(obsmes, "Smoothstep: f(%.1E) = %.1E, f(%.1E) = %.1E, f(%.1E) = %.1E", reg_cont_get[i] -> regthre, maths_hard_step(reg_cont_get[i] -> regthre, reg_cont_get[i] -> regwidt, 0.0, reg_cont_get[i] -> regampl, reg_cont_get[i] -> regthre), reg_cont_get[i] -> regthre+reg_cont_get[i] -> regwidt/2, maths_hard_step(reg_cont_get[i] -> regthre, reg_cont_get[i] -> regwidt, 0.0, reg_cont_get[i] -> regampl, reg_cont_get[i] -> regthre+reg_cont_get[i] -> regwidt/2), reg_cont_get[i] -> regthre+reg_cont_get[i] -> regwidt, maths_hard_step(reg_cont_get[i] -> regthre, reg_cont_get[i] -> regwidt, 0.0, reg_cont_get[i] -> regampl-1.0, reg_cont_get[i] -> regthre+reg_cont_get[i] -> regwidt)); */
/* anyout_tir(&obsint, obsmes); */
/* } */
/**********/
/* done */
return reg_cont_get;
error:
if (varyhstr)
free(varyhstr);
if ((varystr))
freeparsed(varystr);
if ((decomp_controlv))
decomp_dest(decomp_controlv);
if ((decomp_listelvact))
decomp_list_dest(decomp_listelvact);
if ((decomp_listelvden))
decomp_list_dest(decomp_listelvden);
if ((decomp_listelvnum))
decomp_list_dest(decomp_listelvnum);
reg_cont_destr(reg_cont_get);
if ((dummystr))
free(dummystr);
if((regthre))
free(regthre);
if ((regwidt))
free(regwidt);
if ((regampl))
free(regampl);
if ((regaste))
free(regaste);
if ((regampd))
free(regampd);
return NULL;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Constructs a NULL-terminated array of n (empty) reg_containers */
static double reg_do(reg_cont **reg_contv, int loopnr, double chisquare)
{
double reg_do = 0.0;
double addchisq = 0.0;
int i = 0;
int def = 0;
char mes[100];
/**************/
/**************/
/* int obsint = 0; */
/* char obsmes[200]; */
/**************/
if (!reg_contv)
return 1.0;
while ((reg_contv[i])) {
/* read in the parameter */
fourat_put_array(reg_contv[i] -> fc, reg_contv[i] -> first);
/* Calculate the ratio */
if (reg_contv[i] -> regampd > 0.0) {
fourat_rat(reg_contv[i] -> fc, &(reg_contv[i] -> ratio), FOURAT_RAT_SUM);
/*********/
/* sprintf(mes, "Amp (reg): %.2E Amp (par): %.2E Amp (fourat): %.2E", reg_contv[i] -> regampd, *(reg_contv[i] -> first), reg_contv[i] -> ratio); */
/* anyout_tir(&def, mes); */
reg_contv[i] -> ratio = reg_contv[i] -> ratio/reg_contv[i] -> regampd;
}
else {
fourat_rat(reg_contv[i] -> fc, &(reg_contv[i] -> ratio), FOURAT_RAT_RATIO);
}
addchisq = maths_hard_step(reg_contv[i] -> regthre, reg_contv[i] -> regwidt, 0, (reg_contv[i] -> regampl+loopnr*reg_contv[i] -> regaste), reg_contv[i] -> ratio);
/* Calculate reg_do */
reg_do = reg_do+addchisq;
sprintf(mes, "REG group: %i, mode ratio: %.2E, additional chi2: %.2E", i+1, reg_contv[i] -> ratio, addchisq);
anyout_tir(&def, mes);
++i;
}
if ((i)) {
sprintf(mes, "REG total additional chi2: %.2E", reg_do);
anyout_tir(&def, mes);
}
/* That's it */
return reg_do+chisquare;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
static int dec_fill(ringparms *rpm, decomp_control *decomp_controlv)
{
int disk;
char placer[9];
/* ndisk construction */
/* radially dependent parameters */
if ((decomp_inp(decomp_controlv, "RADI", rpm -> nur*PRADI, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VROT", rpm -> nur*PVROT, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VRAD", rpm -> nur*PVRAD, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VVER", rpm -> nur*PVVER, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "DVRO", rpm -> nur*PDVRO, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "DVRA", rpm -> nur*PDVRA, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "DVVE", rpm -> nur*PDVVE, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "ZDRO", rpm -> nur*PZDRO, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "ZDRA", rpm -> nur*PZDRA, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "ZDVE", rpm -> nur*PZDVE, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "Z0", rpm -> nur*PZ0 , rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SBR", rpm -> nur*PSBR , rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM1A", rpm -> nur*PSM1A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM1P", rpm -> nur*PSM1P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM2A", rpm -> nur*PSM2A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM2P", rpm -> nur*PSM2P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM3A", rpm -> nur*PSM3A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM3P", rpm -> nur*PSM3P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM4A", rpm -> nur*PSM4A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SM4P", rpm -> nur*PSM4P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA1A", rpm -> nur*PGA1A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA1P", rpm -> nur*PGA1P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA1D", rpm -> nur*PGA1D, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA2A", rpm -> nur*PGA2A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA2P", rpm -> nur*PGA2P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA2D", rpm -> nur*PGA2D, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA3A", rpm -> nur*PGA3A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA3P", rpm -> nur*PGA3P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA3D", rpm -> nur*PGA3D, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA4A", rpm -> nur*PGA4A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA4P", rpm -> nur*PGA4P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "GA4D", rpm -> nur*PGA4D, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "AZ1P", rpm -> nur*PAZ1P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "AZ1W", rpm -> nur*PAZ1W, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "AZ2P", rpm -> nur*PAZ2P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "AZ2W", rpm -> nur*PAZ2W, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "INCL", rpm -> nur*PINCL, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "PA", rpm -> nur*PPA , rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "XPOS", rpm -> nur*PXPOS, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "YPOS", rpm -> nur*PYPOS, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VSYS", rpm -> nur*PVSYS, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "SDIS", rpm -> nur*PSDIS, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "CLNR", rpm -> nur*PCLNR, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM0A", rpm -> nur*PVM0A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM1A", rpm -> nur*PVM1A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM1P", rpm -> nur*PVM1P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM2A", rpm -> nur*PVM2A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM2P", rpm -> nur*PVM2P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM3A", rpm -> nur*PVM3A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM3P", rpm -> nur*PVM3P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM4A", rpm -> nur*PVM4A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "VM4P", rpm -> nur*PVM4P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA1A", rpm -> nur*PRA1A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA1P", rpm -> nur*PRA1P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA2A", rpm -> nur*PRA2A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA2P", rpm -> nur*PRA2P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA3A", rpm -> nur*PRA3A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA3P", rpm -> nur*PRA3P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA4A", rpm -> nur*PRA4A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RA4P", rpm -> nur*PRA4P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO1A", rpm -> nur*PRO1A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO1P", rpm -> nur*PRO1P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO2A", rpm -> nur*PRO2A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO2P", rpm -> nur*PRO2P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO3A", rpm -> nur*PRO3A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO3P", rpm -> nur*PRO3P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO4A", rpm -> nur*PRO4A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "RO4P", rpm -> nur*PRO4P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM0A", rpm -> nur*PWM0A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM1A", rpm -> nur*PWM1A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM1P", rpm -> nur*PWM1P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM2A", rpm -> nur*PWM2A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM2P", rpm -> nur*PWM2P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM3A", rpm -> nur*PWM3A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM3P", rpm -> nur*PWM3P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM4A", rpm -> nur*PWM4A, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "WM4P", rpm -> nur*PWM4P, rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "LS0", rpm -> nur*PLS0 , rpm -> nur))) goto error;
if ((decomp_inp(decomp_controlv, "LC0", rpm -> nur*PLC0 , rpm -> nur))) goto error;
for (disk = 1; disk < rpm -> ndisks; ++disk) {
sprintf(placer, "VROT_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVROT)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VRAD_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVRAD)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VVER_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVVER)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "DVRO_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PDVRO)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "DVRA_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PDVRA)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "DVVE_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PDVVE)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "ZDRO_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PZDRO)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "ZDRA_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PZDRA)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "ZDVE_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PZDVE)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "Z0_%i" , disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PZ0 )*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SBR_%i" , disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSBR )*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM1A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM1A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM1P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM1P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM2A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM2A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM2P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM2P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM3A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM3A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM3P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM3P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM4A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM4A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SM4P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSM4P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA1A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA1A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA1P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA1P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA1D_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA1D)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA2A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA2A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA2P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA2P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA2D_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA2D)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA3A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA3A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA3P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA3P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA3D_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA3D)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA4A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA4A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA4P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA4P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "GA4D_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PGA4D)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "AZ1P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PAZ1P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "AZ1W_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PAZ1W)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "AZ2P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PAZ2P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "AZ2W_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PAZ2W)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "INCL_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PINCL)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "PA_%i" , disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PPA )*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "XPOS_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PXPOS)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "YPOS_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PYPOS)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VSYS_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVSYS)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "SDIS_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PSDIS)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "CLNR_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PCLNR)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM0A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM0A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM1A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM1A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM1P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM1P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM2A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM2A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM2P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM2P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM3A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM3A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM3P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM3P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM4A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM4A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "VM4P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PVM4P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO1A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO1A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO1P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO1P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO2A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO2A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO2P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO2P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO3A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO3A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO3P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO3P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO4A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO4A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RO4P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRO4P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA1A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA1A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA1P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA1P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA2A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA2A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA2P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA2P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA3A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA3A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA3P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA3P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA4A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA4A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "RA4P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PRA4P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM0A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM0A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM1A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM1A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM1P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM1P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM2A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM2A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM2P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM2P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM3A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM3A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM3P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM3P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM4A_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM4A)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "WM4P_%i", disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PWM4P)*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "LS0_%i" , disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PLS0 )*rpm -> nur, rpm -> nur))) goto error;
sprintf(placer, "LC0_%i" , disk+1); if ((decomp_inp(decomp_controlv, placer, (PRPARAMS+disk*NDPARAMS+PLC0 )*rpm -> nur, rpm -> nur))) goto error;
}
/* global parameters, this needs to be changed somewhat when there is more than one */
if ((decomp_inp(decomp_controlv, "CONDISP", rpm -> nur*(NPARAMS + (rpm -> ndisks - 1)*NDPARAMS), 0))) goto error;
return 0;
error:
decomp_dest(decomp_controlv);
return 1;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Creates a decomp-readable list from inputofvarymult and inputofvarysing and puts it into varyhstr */
static char *gluetodecomp(char **inputofvarymult, char **inputofvarysing)
{
int i, length = 0;
char *returnstring = NULL;
/* varyhstr[0] = '\0'; */
i = 0;
while (inputofvarymult[i] != NULL) {
if (strpbrk(inputofvarymult[i],"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) {
length = length + strlen(", !");
length = length + strlen(inputofvarymult[i]);
}
else {
length = length + strlen(" ");
length = length + strlen(inputofvarymult[i]);
}
++i;
}
i = 0;
while (inputofvarysing[i] != NULL) {
if (strpbrk(inputofvarysing[i],"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) {
length = length + strlen(", ");
length = length + strlen(inputofvarysing[i]);
}
else {
length = length + strlen(" ");
length = length + strlen(inputofvarysing[i]);
}
++i;
}
if (length > 1) {
if (!(returnstring = (char *) malloc((length+1)*sizeof(char))))
return NULL;
returnstring[length] = '\0';
}
else {
if (!(returnstring = (char *) malloc(2*sizeof(char))))
return NULL;
returnstring[0] = '\0';
returnstring[1] = '\0';
}
i = length = 0;
while (inputofvarymult[i] != NULL) {
if (strpbrk(inputofvarymult[i],"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) {
strcpy(returnstring+length, ", !");
length = length + strlen(", !");
strcpy(returnstring+length, inputofvarymult[i]);
length = length + strlen(inputofvarymult[i]);
}
else {
strncpy(returnstring+length, " ", 1);
length = length + strlen(" ");
strcpy(returnstring+length, inputofvarymult[i]);
length = length + strlen(inputofvarymult[i]);
}
++i;
}
while (inputofvarysing[i] != NULL) {
if (strpbrk(inputofvarysing[i],"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")) {
strcpy(returnstring+length, ", ");
length = length + strlen(", ");
strcpy(returnstring+length, inputofvarysing[i]);
length = length + strlen(inputofvarysing[i]);
}
else {
strcpy(returnstring+length, " ");
length = length + strlen(" ");
strcpy(returnstring+length, inputofvarysing[i]);
length = length + strlen(inputofvarysing[i]);
}
++i;
}
if (strlen(returnstring))
returnstring[0] = ' ';
return returnstring;
}
/* ------------------------------------------------------------ */
#ifdef PBCORR
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Allocate memory for primary beam factors */
static void alloc_pbcfac_act(ringparms *rpm, int srnr, int disk)
{
static char mes[180];
static int err = 1;
static long length;
if (!(length = rpm -> sd[disk][srnr].n))
length = 1;
if (!(rpm -> sd[disk][srnr].pbfac = (float *) malloc(length*sizeof(float)))) {
/* Catastrophy, simply stop */
sprintf(mes, "Too many pointsources, increase PFLUX");
error_tir(&err, mes);
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Allocate memory for primary beam factors, dummy */
static void alloc_pbcfac_pas(ringparms *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Deallocate memory for primary beam factors */
static void dealloc_pbcfac_act(ringparms *rpm, int srnr, int disk)
{
if ((rpm -> sd[disk][srnr].pbfac)){
free(rpm -> sd[disk][srnr].pbfac);
rpm -> sd[disk][srnr].pbfac = NULL;
}
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Deallocate memory for primary beam factors, dummy */
static void dealloc_pbcfac_pas(ringparms *rpm, int srnr, int disk)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Fill the pbfac array with the right numbers */
static void fill_pbcfac_act(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid)
{
sd[disk][srnr].pbfac[*pnr] = hdr -> primbeam[grid[0]+ hdr -> bsize1*(grid[1])];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Fill the pbfac array with the right numbers, dummy */
static void fill_pbcfac_pas(hdrinf *hdr, struct srd **sd, int disk, int srnr, long *pnr, int *grid)
{
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Function to fold in the primary beam factor list when constructing the cube */
static void corr_pbcfac_act(struct srd **sd, int disk, int srnr, long pnr)
{
*(sd[disk][srnr].pl[pnr]) += sd[disk][srnr].pf*sd[disk][srnr].pbfac[pnr];
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Function to fold in the primary beam factor list when constructing the cube */
static void corr_pbcfac_pas(struct srd **sd, int disk, int srnr, long pnr)
{
*(sd[disk][srnr].pl[pnr]) += sd[disk][srnr].pf;
return;
}
/* ------------------------------------------------------------ */
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
/* Function to fold in the primary beam factor list when constructing the cube */
static void chkb_pbcorr(hdrinf *hdr, ringparms *rpm)
{
if (hdr -> primbeam) {
rpm -> alloc_pbcfac = alloc_pbcfac_act;
rpm -> dealloc_pbcfac = dealloc_pbcfac_act;
rpm -> fill_pbcfac = fill_pbcfac_act;
rpm -> corr_pbcfac = corr_pbcfac_act;
}
else {
rpm -> alloc_pbcfac = alloc_pbcfac_pas;
rpm -> dealloc_pbcfac = dealloc_pbcfac_pas;
rpm -> fill_pbcfac = fill_pbcfac_pas;
rpm -> corr_pbcfac = corr_pbcfac_pas;
}
}
/* ------------------------------------------------------------ */
#endif
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$Log: tirific_new.c,v $
Revision 1.26 2011/05/25 22:25:26 jozsa
Left work
Revision 1.25 2011/05/11 13:37:12 jozsa
Left work
Revision 1.24 2011/05/10 00:30:16 jozsa
Left work
Revision 1.23 2011/05/04 01:51:03 jozsa
test
Revision 1.22 2011/05/04 01:08:25 jozsa
Left work
Revision 1.21 2011/05/04 01:03:41 jozsa
several changes to make genfitting possible
Revision 1.20 2011/03/23 22:32:29 jozsa
removed hdu 1 and 2, with that all storage of input parameters, left simple check whether tirific has created the file
Revision 1.19 2010/10/14 12:09:46 jozsa
Bugfix: With multiple disks, chkchange did not recognise the disk number correctly
Revision 1.18 2010/07/28 23:04:19 jozsa
Left work
Revision 1.17 2010/04/12 23:15:45 jozsa
included a few things, next is correction of coolgal
Revision 1.16 2010/04/01 09:24:19 jozsa
included and hopefully debugged: radial/vertical movement/gradients of those in z/azimuthal harmonics in velocity and surface brightness. To do 1) subclouds 2) Gaussian variations in azimuth 3) portions of a disk 4) 4 disks
Revision 1.15 2010/03/18 15:49:39 jozsa
implemented interpolation over passive parameters: indexing; implemented new syntax for parameter specification
Revision 1.14 2010/03/08 23:55:38 jozsa
left work
Revision 1.13 2010/03/02 08:23:08 jozsa
several changes, from the following versions on hdu2 is only partially checked for changes against the .def file
Revision 1.12 2009/08/04 16:28:33 jozsa
Left work
Revision 1.11 2009/05/27 15:07:38 jozsa
Left work
Revision 1.10 2008/10/10 15:42:40 jozsa
Introduced radial motion VPS1=
Revision 1.9 2008/07/30 16:22:42 jozsa
Some issue with accuracy in fillhdvarele()
Revision 1.8 2008/06/05 13:04:09 jozsa
left work
Revision 1.12 2008/02/18 16:47:23 gjozsa
graphics SDIS output
Revision 1.11 2008/02/13 16:43:47 gjozsa
silly bug
Revision 1.10 2008/01/16 11:17:24 gjozsa
bugfix concerning sdis
Revision 1.9 2008/01/09 17:50:50 gjozsa
minor bug
Revision 1.8 2008/01/09 17:25:52 gjozsa
introduced ring-dependent dispersion without performance loss
Revision 1.7 2007/08/23 15:23:26 gjozsa
Left work
Revision 1.5 2007/08/16 15:12:05 gjozsa
Left work
Revision 1.4 2007/08/15 16:28:23 gjozsa
Left work
Revision 1.3 2007/08/14 17:09:58 gjozsa
Left work
Revision 1.2 2007/07/25 17:17:09 gjozsa
Left work
Revision 1.1 2007/07/05 16:16:24 gjozsa
added to cvs control
Revision 1.66 2007/03/23 17:21:09 gjozsa
Changed back the changes from rev. 1.64, instead corrected the gridding: If the velocity increases with channel number, the pa changes by 180 deg w.r.t version pre-1.64, otherways it stays. For post-1.64 one has to change the pa by changing its signum and adding or subtracting 180 deg.
Revision 1.65 2007/02/23 10:28:10 gjozsa
BUGFIX in tirout: Works now for TIRACC > 6. Enlargened accuracy in textlog.
Revision 1.64 2007/01/17 15:54:52 gjozsa
Changed coordinate system in srconst by mirroring pp[0] to get a right hand coordinate system. In order not to change the pa definition changed the conversion functions interntoglob globtointern etc. Also did some changes to the graphics functions of which I don't know the effect. One can spot the changes via searching for 180.0 and DEGTORAD in the source
Revision 1.63 2006/12/11 12:42:07 gjozsa
BUGFIX: removed reading beam from header: too much confusion
Revision 1.62 2006/11/22 14:16:21 gjozsa
Bugfix concerning RASH and horizontal/vertical lines
Revision 1.61 2006/11/10 15:53:10 gjozsa
minor bugfix
Revision 1.60 2006/11/09 14:42:55 gjozsa
minor change
Revision 1.59 2006/11/08 14:05:03 gjozsa
included line drawing with keywords GR_VERL_i GR_HORL_i GR_VLVA_i GR_HLVA_i GR_VLCA_i GR_HLCA_i
Revision 1.58 2006/11/03 12:08:59 gjozsa
Small bugfix
Revision 1.57 2006/11/03 10:57:38 gjozsa
Introduced logarithmic scaling keywords: GR_XLOG, GR_YLOG_i, introduced hms dms for xpos and ypos in graphics output, introduced keywords RFREQ (restfrequency in Hertz) and ITOU (conversion factor from intensity in Jy/squarearcsec in u/squarecentimeter), changed DOUBLE_ACCURACY to 3E-15 to account for near zero events
Revision 1.56 2006/07/18 09:33:02 gjozsa
Left work
Revision 1.55 2006/04/11 11:46:00 gjozsa
Removed the positive SBR restriction in input
Revision 1.54 2006/04/06 10:40:25 gjozsa
Bugfix: Call of engalmod_chflgs() after changing the input cube after chisquare initialisation
Revision 1.53 2006/04/03 11:47:57 gjozsa
Left work
Revision 1.52 2005/10/12 14:50:59 gjozsa
Not really a Bugfix: Corrected the calculation of the ring normal vector
Revision 1.51 2005/10/12 09:53:45 gjozsa
Included Brigg's plots
Revision 1.50 2005/09/29 17:46:00 gjozsa
BUGFIX in the golden_section() function: refreshing pointsource lists is a crucial point
Revision 1.49 2005/08/25 10:15:05 gjozsa
Slight bug in the plot routines
Revision 1.48 2005/08/18 13:06:52 gjozsa
Left work
Revision 1.47 2005/08/15 13:15:03 gjozsa
BUGFIX: At 12523, not copying to the par array will result in funny results, when the only output is a .def file. Don't know whether this will cause sequals
Revision 1.45 2005/07/27 14:27:34 gjozsa
Again improved the graphics output
Revision 1.44 2005/07/27 14:01:30 gjozsa
Improved the graphics output
Revision 1.43 2005/06/28 13:28:08 gjozsa
Changed the out of range behaviour in golden_section()
Revision 1.42 2005/06/24 16:44:51 gjozsa
added interpolation possibility for the TIRDEF= output, not yet for TIRSMOOTH=
Revision 1.41 2005/06/24 12:00:30 gjozsa
Left work
Revision 1.43 2005/06/17 14:56:45 gjozsa
Bugfix
Revision 1.42 2005/06/17 14:50:45 gjozsa
Bugfix
Revision 1.41 2005/06/17 14:23:48 gjozsa
Added penalty for outliers
Revision 1.40 2005/06/13 10:40:29 gjozsa
Added possibility just to examine results
Revision 1.39 2005/06/09 14:07:45 gjozsa
Left work
Revision 1.38 2005/06/09 08:22:58 gjozsa
BUGFIX: Multiple Parameter fitting was not working properly, fixed that
Revision 1.37 2005/05/25 15:47:39 gjozsa
Added inclinogram output
Revision 1.36 2005/05/24 15:59:08 gjozsa
Added LON and LMV to table output
Revision 1.34 2005/05/24 10:42:03 gjozsa
Included graphics
Revision 1.33 2005/05/03 12:42:18 gjozsa
Left work
Revision 1.32 2005/04/28 12:44:44 gjozsa
bugfix
Revision 1.31 2005/04/28 10:13:47 gjozsa
Full introduction of pointsource lists
Revision 1.28 2005/04/26 11:44:53 gjozsa
Seems to work
Revision 1.25 2005/04/20 14:33:39 gjozsa
bug
Revision 1.24 2005/04/20 13:26:25 gjozsa
Left work
Revision 1.23 2005/04/19 13:58:50 gjozsa
Left work
Revision 1.22 2005/04/19 15:29:28 gjozsa
Finished the output functions
Revision 1.21 2005/04/19 10:59:13 gjozsa
Extended the possibilities for the histogram output
Revision 1.19 2005/04/19 07:44:43 gjozsa
Left work
Revision 1.18 2005/04/18 15:53:40 gjozsa
Added histogram functions
Revision 1.17 2005/04/18 15:02:02 gjozsa
Included TIR functions
Revision 1.16 2005/04/15 15:52:09 gjozsa
Left work
Revision 1.15 2005/04/15 15:39:13 gjozsa
Bugfix: in fct get_ringparms, documented as BUGFIX , in fct decodestring, also reported
Revision 1.14 2005/04/14 14:26:05 gjozsa
Left work
Revision 1.13 2005/04/14 10:32:16 gjozsa
Left work
Revision 1.10 2005/04/12 14:54:33 gjozsa
Changed the character of PARMAX= and PARMIN=
Revision 1.9 2005/04/11 14:23:37 gjozsa
Left work
Revision 1.8 2005/04/08 15:30:40 gjozsa
Taking into account the whole cube now, no counting for the user
Revision 1.7 2005/04/08 07:27:44 gjozsa
Bugfixes
Revision 1.6 2005/04/08 07:25:59 gjozsa
Bugfixes
Revision 1.5 2005/04/07 15:15:16 gjozsa
Bugfix in galmod(): subring velocity was overwritten by a radius, I hacked a bit, not nic at the moment
Revision 1.3 2005/04/06 15:46:25 gjozsa
Bugfixes, included monitoring of golden_section
Revision 1.2 2005/04/05 16:06:06 gjozsa
Left work
Revision 1.1 2005/04/05 11:07:37 gjozsa
The former tiridev, officially release 1
Revision 1.41 2005/04/04 08:42:09 gjozsa
removed bug
Revision 1.40 2005/04/01 15:31:54 gjozsa
Introduced writecubup and a lot of debugging, check whether the output is not too large
Revision 1.39 2005/03/29 15:56:24 gjozsa
left work
Revision 1.36 2005/03/25 18:17:20 gjozsa
Left work
Revision 1.35 2005/03/23 17:48:49 gjozsa
Implemented hdu_3 support, seems to work
Revision 1.32 2005/03/23 13:44:33 gjozsa
Implemented and tested 2nd hdu i/o
Revision 1.31 2005/03/22 17:48:07 gjozsa
Left work
Revision 1.30 2005/03/21 18:54:17 gjozsa
Left work
Revision 1.29 2005/03/19 17:55:52 gjozsa
Left work
Revision 1.26 2005/03/17 18:00:50 gjozsa
Left work
Revision 1.25 2005/03/16 17:52:00 gjozsa
Left work
Revision 1.23 2005/03/15 18:53:08 gjozsa
Left work
Revision 1.22 2005/03/15 17:28:59 gjozsa
Last changes to get a clear program structure, not ideal, but ok. Some debugging, deleting the fortran thingies
Revision 1.21 2005/03/12 16:48:33 gjozsa
Removed all clutter from readringparms and associated structs
Revision 1.19 2005/03/12 13:24:49 gjozsa
Removed all clutter from hdrinit
Revision 1.17 2005/03/12 11:37:46 gjozsa
Rearranged completely galmod, debugged and tested version of new galmod, including convolution routines, changed position angle to angle with respect to minor
Revision 1.16 2005/03/11 17:45:55 gjozsa
Left work
Revision 1.15 2005/03/10 17:56:39 gjozsa
Left work
Revision 1.13 2005/03/08 17:55:07 gjozsa
Left work
Revision 1.12 2005/03/05 17:56:09 gjozsa
Left work
Revision 1.11 2005/03/04 18:13:53 gjozsa
Left work
Revision 1.10 2005/03/03 18:00:49 gjozsa
Left work
Revision 1.9 2005/03/02 17:56:09 gjozsa
Left work
Revision 1.8 2005/03/01 17:46:21 gjozsa
Left work
Revision 1.6 2005/02/25 18:13:08 gjozsa
Left work
Revision 1.5 2005/02/25 13:34:29 gjozsa
cube io finished
Revision 1.4 2005/02/25 11:38:27 gjozsa
Created a header struct
Revision 1.3 2005/02/24 17:48:46 gjozsa
Left work
Revision 1.2 2004/12/09 16:17:14 gjozsa
Changed some floating point operations from double to float accuracy
Revision 1.1.1.1 2004/10/29 11:13:20 gjozsa
Added to CVS control
------------------------------------------------------------ */
| {
"alphanum_fraction": 0.5616450385,
"avg_line_length": 36.2661067367,
"ext": "c",
"hexsha": "831de2b4fd4c581b2a97a4725d71a98c1203c007",
"lang": "C",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-03T15:02:35.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-28T03:17:38.000Z",
"max_forks_repo_head_hexsha": "05fddee80e715dfee5d0f4e2f994b2f17c5d2ca9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kernsuite-debian/tirific",
"max_forks_repo_path": "src/tirific.c",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "462a58a8312ce437ac5e2c87060cde751774f1de",
"max_issues_repo_issues_event_max_datetime": "2019-08-20T06:37:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-02-24T12:40:08.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "gigjozsa/tirific",
"max_issues_repo_path": "src/tirific.c",
"max_line_length": 693,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "05fddee80e715dfee5d0f4e2f994b2f17c5d2ca9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kernsuite-debian/tirific",
"max_stars_repo_path": "src/tirific.c",
"max_stars_repo_stars_event_max_datetime": "2018-01-04T08:22:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-01T12:07:09.000Z",
"num_tokens": 321297,
"size": 1036304
} |
/*
Ballistic: a software to benchmark ballistic models.
AUTHORS: Javier Burguete Tolosa.
Copyright 2018, AUTHORS.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGE.
*/
/**
* \file ballistic.c
* \brief Source file with the main function.
* \author Javier Burguete Tolosa.
* \copyright Copyright 2018.
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <gsl/gsl_rng.h>
#include <libxml/parser.h>
#include <glib.h>
#include "config.h"
#include "utils.h"
#include "equation.h"
#include "method.h"
#include "runge-kutta.h"
#include "multi-steps.h"
#define DEBUG_BALLISTIC 0 ///< macro to debug the ballistic functions.
long double convergence_factor;
///< convergence factor.
unsigned int ntrajectories;
///< number of projectil trajectories to calculate.
unsigned int convergence;
///< number of convergence steps.
/**
* Function to read the basic input data.
*
* \return 1 on success, 0 on error.
*/
static inline int
convergence_read_xml (xmlNode * node) ///< XML node.
{
const char *message[] = {
"Bad trajectories number",
"Bad convergence steps",
"Bad convergence factor"
};
int e, error_code;
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_read_xml: start\n");
#endif
ntrajectories = xml_node_get_uint (node, XML_TRAJECTORIES, &error_code);
if (error_code || !ntrajectories)
{
e = 0;
goto fail;
}
convergence = xml_node_get_uint (node, XML_CONVERGENCE, &error_code);
if (error_code || !convergence)
{
e = 1;
goto fail;
}
convergence_factor = xml_node_get_float (node, XML_FACTOR, &error_code);
if (error_code || convergence_factor <= 0.)
{
e = 2;
goto fail;
}
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_read_xml: success\n");
fprintf (stderr, "convergence_read_xml: end\n");
#endif
return 1;
fail:
error_add (message[e]);
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_read_xml: error\n");
fprintf (stderr, "convergence_read_xml: end\n");
#endif
return 0;
}
/**
* Function to open a numerical method on a XML node.
*
* \return 0 on error, 1 on Runge-Kutta method, 2 on multi-steps method.
*/
static inline int
method_open_xml (MultiSteps * ms,
RungeKutta * rk,
xmlNode * node)
{
char *message[] = {
"No numerical method XML node",
"Bad Runge-Kutta data",
"Bad multi-steps data",
"Unknown numerical method"
};
int e, m;
#if DEBUG_BALLISTIC
fprintf (stderr, "method_open_xml: start\n");
#endif
if (!node)
{
e = 0;
goto fail;
}
if (!xmlStrcmp (node->name, XML_RUNGE_KUTTA))
{
if (!runge_kutta_read_xml (rk, node))
{
e = 1;
goto fail;
}
runge_kutta_init_variables (rk);
m = 1;
}
else if (!xmlStrcmp (node->name, XML_MULTI_STEPS))
{
if (!multi_steps_read_xml (ms, node))
{
e = 2;
goto fail;
}
multi_steps_init_variables (ms);
m = 2;
}
else
{
e = 3;
goto fail;
}
#if DEBUG_BALLISTIC
fprintf (stderr, "method_open_xml: success\n");
fprintf (stderr, "method_open_xml: end\n");
#endif
return m;
fail:
error_add (message[e]);
#if DEBUG_BALLISTIC
fprintf (stderr, "method_open_xml: error\n");
fprintf (stderr, "method_open_xml: end\n");
#endif
return 0;
}
/**
* Function to show the error message.
*/
static void
show_error ()
{
printf ("ERROR!\n%s", error_message);
g_free (error_message);
error_message = NULL;
}
/**
* Function to print the solution values.
*/
static void
print_solution (char *label, ///< label.
long double *r0, ///< position vector.
long double *r1) ///< velocity vector.
{
printf ("%s\n", label);
printf ("x = %.19Le\n", r0[0]);
printf ("y = %.19Le\n", r0[1]);
printf ("z = %.19Le\n", r0[2]);
printf ("vx = %.19Le\n", r1[0]);
printf ("vy = %.19Le\n", r1[1]);
printf ("vz = %.19Le\n", r1[2]);
}
/**
* Function to print the numerical errors.
*/
static void
print_error (char *label, ///< label.
long double *r1, ///< numerical solution vector.
long double *r2) ///< analytical solution vector.
{
printf ("%s = %.19Le\n", label, distance (r1, r2));
}
/**
* Function to perform a convergence analysis of a method.
*
* \return 0 on success, error code on error.
*/
static inline int
convergence_run (xmlNode * node, ///< XML node.
char *output) ///< results file name.
{
const char *message[] = {
NULL,
"Bad convergence data",
"No equation XML node",
"Unknown numerical method",
"Bad numerical method data"
};
MultiSteps ms[1];
RungeKutta rk[1];
Equation eq[1];
Method *m;
gsl_rng *rng;
FILE *file;
long double sr0[3], sr1[3];
long double t, l0r0, l2r0, l0r1, l2r1, e;
int er, me;
unsigned int i, j;
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: start\n");
#endif
er = 0;
if (!convergence_read_xml (node))
{
er = 1;
goto fail;
}
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: initing equation\n");
#endif
node = node->children;
if (!node)
{
er = 2;
goto fail;
}
if (!equation_read_xml (eq, node, 0))
{
er = 3;
goto fail;
}
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: initing method\n");
#endif
node = node->next;
me = method_open_xml (ms, rk, node);
switch (me)
{
case 1:
m = RUNGE_KUTTA_METHOD (rk);
break;
case 2:
m = MULTI_STEPS_METHOD (ms);
break;
default:
er = 4;
goto fail;
}
rng = gsl_rng_alloc (gsl_rng_taus2);
file = fopen (output, "w");
for (j = 0; j < convergence; ++j)
{
gsl_rng_set (rng, 0l);
nevaluations = 0l;
l0r0 = l2r0 = l0r1 = l2r1 = 0.L;
for (i = 0; i < ntrajectories; ++i)
{
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: initing equation data\n");
#endif
equation_init (eq, rng);
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: initing variables\n");
#endif
equation_solution (eq, r0, r1, 0.);
equation_acceleration (eq, r0, r1, r2, 0.L);
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: running\n");
#endif
if (me == 1)
t = runge_kutta_run (rk, eq);
else
t = multi_steps_run (ms, eq);
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: solutions\n");
print_solution ("Numerical solution", r0, r1);
printf ("Time = %.19Le\n", t);
#endif
switch (eq->land_type)
{
case 0:
equation_solution (eq, sr0, sr1, eq->tf);
break;
default:
t = equation_solve (eq, sr0, sr1);
}
#if DEBUG_BALLISTIC
print_solution ("Analytical solution", sr0, sr1);
printf ("Time = %.19Le\n", t);
print_error ("Position error", r0, sr0);
print_error ("Velocity error", r1, sr1);
#endif
e = distance (r0, sr0);
l0r0 = fmaxl (l0r0, e);
l2r0 += e * e;
e = distance (r1, sr1);
l0r1 = fmaxl (l0r1, e);
l2r1 += e * e;
}
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: saving results\n");
#endif
l2r0 = sqrtl (l2r0 / ntrajectories);
l2r1 = sqrtl (l2r1 / ntrajectories);
fprintf (file, "%lu %.19Le %.19Le %.19Le %.19Le %.19Le %.19Le\n",
nevaluations, l0r0, l2r0, l0r1, l2r1, kt, m->emt);
switch (eq->size_type)
{
case 0:
dt *= convergence_factor;
break;
default:
kt *= convergence_factor;
}
m->emt *= convergence_factor;
if (me == 2)
RUNGE_KUTTA_METHOD (MULTI_STEPS_RUNGE_KUTTA (ms))->emt
*= convergence_factor;
}
fclose (file);
printf ("Time = %.19Le\n", t);
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: deleting method\n");
#endif
if (me == 1)
runge_kutta_delete (rk);
else
multi_steps_delete (ms);
gsl_rng_free (rng);
fail:
if (er)
{
error_add (message[er]);
show_error ();
}
#if DEBUG_BALLISTIC
fprintf (stderr, "convergence_run: end\n");
#endif
return 0;
}
/**
* Function to calculate a ballistic trajectory.
*
* \return 0 on success, error code on error.
*/
static inline int
ballistic_run (xmlNode * node) ///< XML node.
{
const char *message[] = {
NULL,
"Unable to open the XML root element",
"Bad XML file",
"No equation XML node",
"Bad equation data",
};
MultiSteps ms[1];
RungeKutta rk[1];
Equation eq[1];
long double sr0[3], sr1[3];
long double t;
int e, m;
#if DEBUG_BALLISTIC
fprintf (stderr, "ballistic_run: start\n");
#endif
e = 0;
node = node->children;
if (!node)
{
e = 3;
goto end;
}
if (!equation_read_xml (eq, node, 1))
{
e = 4;
goto end;
}
node = node->next;
if (!node)
{
e = 5;
goto end;
}
if (!xmlStrcmp (node->name, XML_RUNGE_KUTTA))
{
if (!runge_kutta_read_xml (rk, node))
{
e = 6;
goto end;
}
runge_kutta_init_variables (rk);
m = 1;
}
else if (!xmlStrcmp (node->name, XML_MULTI_STEPS))
{
if (!multi_steps_read_xml (ms, node))
{
e = 7;
goto end;
}
multi_steps_init_variables (ms);
m = 2;
}
else
{
e = 8;
goto end;
}
nevaluations = 0l;
#if DEBUG_BALLISTIC
fprintf (stderr, "ballistic_run: initing variables\n");
#endif
equation_solution (eq, r0, r1, 0.);
equation_acceleration (eq, r0, r1, r2, 0.L);
#if DEBUG_BALLISTIC
fprintf (stderr, "ballistic_run: running\n");
#endif
switch (m)
{
case 1:
t = runge_kutta_run (rk, eq);
break;
default:
t = multi_steps_run (ms, eq);
}
#if DEBUG_BALLISTIC
fprintf (stderr, "ballistic_run: solutions\n");
#endif
print_solution ("Numerical solution", r0, r1);
printf ("Time = %.19Le\n", t);
switch (eq->land_type)
{
case 0:
equation_solution (eq, sr0, sr1, eq->tf);
break;
default:
t = equation_solve (eq, sr0, sr1);
}
print_solution ("Analytical solution", sr0, sr1);
printf ("Time = %.19Le\n", t);
print_error ("Position error", r0, sr0);
print_error ("Velocity error", r1, sr1);
printf ("Time = %.19Le\n", t);
#if DEBUG_BALLISTIC
fprintf (stderr, "ballistic_run: deleting method\n");
#endif
switch (m)
{
case 1:
runge_kutta_delete (rk);
break;
default:
multi_steps_delete (ms);
}
end:
#if DEBUG_BALLISTIC
fprintf (stderr, "ballistic_run: end\n");
#endif
if (e)
error_add (message[e]);
return e;
}
/**
* Main function
*
* \return 0 on success, error code otherwise.
*/
int
main (int argn, ///< number of arguments.
char **argc) ///< array of argument chars.
{
const char *message[] = {
NULL,
"The syntax is:\n./ballistic input_file output_file\n",
"Unable to open the input file",
"Bad XML root element",
"Bad ballistic run",
"Bad convergence run",
"Unknown model"
};
xmlDoc *doc;
xmlNode *node;
int e;
#if DEBUG_BALLISTIC
fprintf (stderr, "main: start\n");
#endif
e = 0;
if (argn != 3)
{
e = 1;
goto end;
}
xmlKeepBlanksDefault (0);
doc = xmlParseFile (argc[1]);
if (!doc)
{
e = 2;
goto end;
}
node = xmlDocGetRootElement (doc);
if (!node)
{
e = 3;
goto end;
}
if (!xmlStrcmp (node->name, XML_BALLISTIC))
{
e = ballistic_run (node);
if (e)
{
e = 4;
goto end;
}
}
else if (!xmlStrcmp (node->name, XML_CONVERGENCE))
{
e = convergence_run (node, argc[2]);
if (e)
{
e = 5;
goto end;
}
}
else
e = 6;
xmlFreeDoc (doc);
end:
if (e)
{
error_add (message[e]);
show_error ();
}
return e;
}
| {
"alphanum_fraction": 0.6070175439,
"avg_line_length": 22.9597197898,
"ext": "c",
"hexsha": "933ad38b0999bfb458443fd8c650729191ff491e",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-06-24T07:19:47.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-06-24T07:19:47.000Z",
"max_forks_repo_head_hexsha": "e557bce6e63bb667f1e698cff6e68013bb4e5e6f",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "jburguete/ballistic",
"max_forks_repo_path": "1.1.0/ballistic.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e557bce6e63bb667f1e698cff6e68013bb4e5e6f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "jburguete/ballistic",
"max_issues_repo_path": "1.1.0/ballistic.c",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "e557bce6e63bb667f1e698cff6e68013bb4e5e6f",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "jburguete/ballistic",
"max_stars_repo_path": "1.1.0/ballistic.c",
"max_stars_repo_stars_event_max_datetime": "2020-08-02T14:03:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-08-02T14:03:09.000Z",
"num_tokens": 3809,
"size": 13110
} |
/* ode-initval/odeiv2.h
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* 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 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
* 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.
*/
/* Author: G. Jungman */
/* Modified by Tuomo Keskitalo */
#ifndef __GSL_ODEIV2_H__
#define __GSL_ODEIV2_H__
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_types.h>
#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif
__BEGIN_DECLS
/* Description of a system of ODEs.
*
* y' = f(t,y) = dydt(t, y)
*
* The system is specified by giving the right-hand-side
* of the equation and possibly a jacobian function.
*
* Some methods require the jacobian function, which calculates
* the matrix dfdy and the vector dfdt. The matrix dfdy conforms
* to the GSL standard, being a continuous range of floating point
* values, in row-order.
*
* As with GSL function objects, user-supplied parameter
* data is also present.
*/
typedef struct
{
int (*function) (double t, const double y[], double dydt[], void *params);
int (*jacobian) (double t, const double y[], double *dfdy, double dfdt[],
void *params);
size_t dimension;
void *params;
}
gsl_odeiv2_system;
/* Function evaluation macros */
#define GSL_ODEIV_FN_EVAL(S,t,y,f) (*((S)->function))(t,y,f,(S)->params)
#define GSL_ODEIV_JA_EVAL(S,t,y,dfdy,dfdt) (*((S)->jacobian))(t,y,dfdy,dfdt,(S)->params)
/* Type definitions */
typedef struct gsl_odeiv2_step_struct gsl_odeiv2_step;
typedef struct gsl_odeiv2_control_struct gsl_odeiv2_control;
typedef struct gsl_odeiv2_evolve_struct gsl_odeiv2_evolve;
typedef struct gsl_odeiv2_driver_struct gsl_odeiv2_driver;
/* Stepper object
*
* Opaque object for stepping an ODE system from t to t+h.
* In general the object has some state which facilitates
* iterating the stepping operation.
*/
typedef struct
{
const char *name;
int can_use_dydt_in;
int gives_exact_dydt_out;
void *(*alloc) (size_t dim);
int (*apply) (void *state, size_t dim, double t, double h, double y[],
double yerr[], const double dydt_in[], double dydt_out[],
const gsl_odeiv2_system * dydt);
int (*set_driver) (void *state, const gsl_odeiv2_driver * d);
int (*reset) (void *state, size_t dim);
unsigned int (*order) (void *state);
void (*free) (void *state);
}
gsl_odeiv2_step_type;
struct gsl_odeiv2_step_struct
{
const gsl_odeiv2_step_type *type;
size_t dimension;
void *state;
};
/* Available stepper types */
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rk2;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rk4;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rkf45;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rkck;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rk8pd;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rk2imp;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rk4imp;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_bsimp;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_rk1imp;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_msadams;
GSL_VAR const gsl_odeiv2_step_type *gsl_odeiv2_step_msbdf;
/* Stepper object methods */
gsl_odeiv2_step *gsl_odeiv2_step_alloc (const gsl_odeiv2_step_type * T,
size_t dim);
int gsl_odeiv2_step_reset (gsl_odeiv2_step * s);
void gsl_odeiv2_step_free (gsl_odeiv2_step * s);
const char *gsl_odeiv2_step_name (const gsl_odeiv2_step * s);
unsigned int gsl_odeiv2_step_order (const gsl_odeiv2_step * s);
int gsl_odeiv2_step_apply (gsl_odeiv2_step * s, double t, double h,
double y[], double yerr[], const double dydt_in[],
double dydt_out[], const gsl_odeiv2_system * dydt);
int gsl_odeiv2_step_set_driver (gsl_odeiv2_step * s,
const gsl_odeiv2_driver * d);
/* Step size control object. */
typedef struct
{
const char *name;
void *(*alloc) (void);
int (*init) (void *state, double eps_abs, double eps_rel, double a_y,
double a_dydt);
int (*hadjust) (void *state, size_t dim, unsigned int ord, const double y[],
const double yerr[], const double yp[], double *h);
int (*errlevel) (void *state, const double y, const double dydt,
const double h, const size_t ind, double *errlev);
int (*set_driver) (void *state, const gsl_odeiv2_driver * d);
void (*free) (void *state);
}
gsl_odeiv2_control_type;
struct gsl_odeiv2_control_struct
{
const gsl_odeiv2_control_type *type;
void *state;
};
/* Possible return values for an hadjust() evolution method */
#define GSL_ODEIV_HADJ_INC 1 /* step was increased */
#define GSL_ODEIV_HADJ_NIL 0 /* step unchanged */
#define GSL_ODEIV_HADJ_DEC (-1) /* step decreased */
/* General step size control methods.
*
* The hadjust() method controls the adjustment of
* step size given the result of a step and the error.
* Valid hadjust() methods must return one of the codes below.
* errlevel function calculates the desired error level D0.
*
* The general data can be used by specializations
* to store state and control their heuristics.
*/
gsl_odeiv2_control *gsl_odeiv2_control_alloc (const gsl_odeiv2_control_type *
T);
int gsl_odeiv2_control_init (gsl_odeiv2_control * c, double eps_abs,
double eps_rel, double a_y, double a_dydt);
void gsl_odeiv2_control_free (gsl_odeiv2_control * c);
int gsl_odeiv2_control_hadjust (gsl_odeiv2_control * c, gsl_odeiv2_step * s,
const double y[], const double yerr[],
const double dydt[], double *h);
const char *gsl_odeiv2_control_name (const gsl_odeiv2_control * c);
int gsl_odeiv2_control_errlevel (gsl_odeiv2_control * c, const double y,
const double dydt, const double h,
const size_t ind, double *errlev);
int gsl_odeiv2_control_set_driver (gsl_odeiv2_control * c,
const gsl_odeiv2_driver * d);
/* Available control object constructors.
*
* The standard control object is a four parameter heuristic
* defined as follows:
* D0 = eps_abs + eps_rel * (a_y |y| + a_dydt h |y'|)
* D1 = |yerr|
* q = consistency order of method (q=4 for 4(5) embedded RK)
* S = safety factor (0.9 say)
*
* / (D0/D1)^(1/(q+1)) D0 >= D1
* h_NEW = S h_OLD * |
* \ (D0/D1)^(1/q) D0 < D1
*
* This encompasses all the standard error scaling methods.
*
* The y method is the standard method with a_y=1, a_dydt=0.
* The yp method is the standard method with a_y=0, a_dydt=1.
*/
gsl_odeiv2_control *gsl_odeiv2_control_standard_new (double eps_abs,
double eps_rel,
double a_y,
double a_dydt);
gsl_odeiv2_control *gsl_odeiv2_control_y_new (double eps_abs, double eps_rel);
gsl_odeiv2_control *gsl_odeiv2_control_yp_new (double eps_abs,
double eps_rel);
/* This controller computes errors using different absolute errors for
* each component
*
* D0 = eps_abs * scale_abs[i] + eps_rel * (a_y |y| + a_dydt h |y'|)
*/
gsl_odeiv2_control *gsl_odeiv2_control_scaled_new (double eps_abs,
double eps_rel, double a_y,
double a_dydt,
const double scale_abs[],
size_t dim);
/* Evolution object */
struct gsl_odeiv2_evolve_struct
{
size_t dimension;
double *y0;
double *yerr;
double *dydt_in;
double *dydt_out;
double last_step;
unsigned long int count;
unsigned long int failed_steps;
const gsl_odeiv2_driver *driver;
};
/* Evolution object methods */
gsl_odeiv2_evolve *gsl_odeiv2_evolve_alloc (size_t dim);
int gsl_odeiv2_evolve_apply (gsl_odeiv2_evolve * e, gsl_odeiv2_control * con,
gsl_odeiv2_step * step,
const gsl_odeiv2_system * dydt, double *t,
double t1, double *h, double y[]);
int gsl_odeiv2_evolve_apply_fixed_step (gsl_odeiv2_evolve * e,
gsl_odeiv2_control * con,
gsl_odeiv2_step * step,
const gsl_odeiv2_system * dydt,
double *t, const double h0,
double y[]);
int gsl_odeiv2_evolve_reset (gsl_odeiv2_evolve * e);
void gsl_odeiv2_evolve_free (gsl_odeiv2_evolve * e);
int gsl_odeiv2_evolve_set_driver (gsl_odeiv2_evolve * e,
const gsl_odeiv2_driver * d);
/* Driver object
*
* This is a high level wrapper for step, control and
* evolve objects.
*/
struct gsl_odeiv2_driver_struct
{
const gsl_odeiv2_system *sys; /* ODE system */
gsl_odeiv2_step *s; /* stepper object */
gsl_odeiv2_control *c; /* control object */
gsl_odeiv2_evolve *e; /* evolve object */
double h; /* step size */
double hmin; /* minimum step size allowed */
double hmax; /* maximum step size allowed */
unsigned long int n; /* number of steps taken */
unsigned long int nmax; /* Maximum number of steps allowed */
};
/* Driver object methods */
gsl_odeiv2_driver *gsl_odeiv2_driver_alloc_y_new (const gsl_odeiv2_system *
sys,
const gsl_odeiv2_step_type *
T, const double hstart,
const double epsabs,
const double epsrel);
gsl_odeiv2_driver *gsl_odeiv2_driver_alloc_yp_new (const gsl_odeiv2_system *
sys,
const gsl_odeiv2_step_type
* T, const double hstart,
const double epsabs,
const double epsrel);
gsl_odeiv2_driver *gsl_odeiv2_driver_alloc_scaled_new (const gsl_odeiv2_system
* sys,
const
gsl_odeiv2_step_type *
T, const double hstart,
const double epsabs,
const double epsrel,
const double a_y,
const double a_dydt,
const double
scale_abs[]);
gsl_odeiv2_driver *gsl_odeiv2_driver_alloc_standard_new (const
gsl_odeiv2_system *
sys,
const
gsl_odeiv2_step_type
* T,
const double hstart,
const double epsabs,
const double epsrel,
const double a_y,
const double a_dydt);
int gsl_odeiv2_driver_set_hmin (gsl_odeiv2_driver * d, const double hmin);
int gsl_odeiv2_driver_set_hmax (gsl_odeiv2_driver * d, const double hmax);
int gsl_odeiv2_driver_set_nmax (gsl_odeiv2_driver * d,
const unsigned long int nmax);
int gsl_odeiv2_driver_apply (gsl_odeiv2_driver * d, double *t,
const double t1, double y[]);
int gsl_odeiv2_driver_apply_fixed_step (gsl_odeiv2_driver * d, double *t,
const double h,
const unsigned long int n,
double y[]);
int gsl_odeiv2_driver_reset (gsl_odeiv2_driver * d);
void gsl_odeiv2_driver_free (gsl_odeiv2_driver * state);
__END_DECLS
#endif /* __GSL_ODEIV2_H__ */
| {
"alphanum_fraction": 0.5818978102,
"avg_line_length": 41.1411411411,
"ext": "h",
"hexsha": "3134a1efd14f990ba69c08e7e9e3ae56c2b7cba1",
"lang": "C",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-08-30T20:40:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-08-30T20:40:25.000Z",
"max_forks_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ielomariala/Hex-Game",
"max_forks_repo_path": "gsl-2.6/gsl/gsl_odeiv2.h",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "ielomariala/Hex-Game",
"max_issues_repo_path": "gsl-2.6/gsl/gsl_odeiv2.h",
"max_line_length": 89,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2c2e7c85f8414cb0e654cb82e9686cce5e75c63a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ielomariala/Hex-Game",
"max_stars_repo_path": "gsl-2.6/gsl/gsl_odeiv2.h",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3284,
"size": 13700
} |
/*
** compute histogram density function
**
** G.Lohmann, Nov 2012
*/
#include <viaio/Vlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_histogram.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_math.h>
#define SQR(x) ((x)*(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
/* kernel density estimation */
double GaussKernel(double x)
{
return exp(-0.5*x*x)/sqrt(2.0*M_PI);
}
double VKernelDensity(double x,double h,double nh,gsl_histogram *histogram)
{
size_t i;
double sum,upper,lower;
sum = 0;
for (i=0; i<gsl_histogram_bins(histogram); i++) {
double nx = gsl_histogram_get (histogram,i);
gsl_histogram_get_range (histogram,i,&lower,&upper);
double xi = lower + (upper-lower)*0.5;
double u = (x-xi)/h;
sum += nx * GaussKernel(u);
}
return sum/nh;
}
void VPrintHistogram(gsl_histogram *histogram,int numperm,VString filename)
{
size_t i;
double z=0,mx=0,lower=0,upper=0,fz=0;
extern double GaussKernel(double x);
extern double VKernelDensity(double,double,double,gsl_histogram *);
gsl_histogram_get_range (histogram,0,&lower,&upper);
double alpha = 1.06; /* silverman's rule */
double sig = gsl_histogram_sigma(histogram);
double kx = gsl_histogram_sum(histogram);
double h = alpha * sig * pow(kx,-0.2);
double nh = h*kx;
FILE *fph = fopen(filename,"w");
if (!fph) VError(" err opening hist file");
for (i=0; i<gsl_histogram_bins(histogram); i++) {
gsl_histogram_get_range (histogram,i,&lower,&upper);
z = lower;
fz = VKernelDensity(z,h,nh,histogram);
mx = gsl_histogram_get (histogram,i);
fprintf(fph,"%lf %lf %.2lf\n",lower,fz,mx);
}
fclose(fph);
}
/* update histogram */
void HistoUpdate(float *A,size_t nvox,gsl_histogram *hist)
{
double tiny = 1.0e-8;
size_t i,j;
double hmin = gsl_histogram_min(hist);
double hmax = gsl_histogram_max(hist);
for (i=0; i<nvox; i++) {
for (j=0; j<i; j++) {
const size_t k=j+i*(i+1)/2;
double u = (double)A[k];
if (ABS(u) < tiny) continue;
if (u < hmin) u = hmin;
if (u > hmax-tiny) u = hmax-tiny;
gsl_histogram_increment (hist,u);
}
}
}
| {
"alphanum_fraction": 0.6493902439,
"avg_line_length": 24.4255319149,
"ext": "c",
"hexsha": "d48db6ddd54bb09d8f03f8fbe4cf2da03d337199",
"lang": "C",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2022-03-22T08:05:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-09-29T10:33:53.000Z",
"max_forks_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zrajna/lipsia",
"max_forks_repo_path": "src/ted/vted/Histogram.c",
"max_issues_count": 7,
"max_issues_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014",
"max_issues_repo_issues_event_max_datetime": "2022-02-16T13:42:05.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-11-12T15:47:56.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zrajna/lipsia",
"max_issues_repo_path": "src/ted/vted/Histogram.c",
"max_line_length": 75,
"max_stars_count": 17,
"max_stars_repo_head_hexsha": "8e7252653bd641df8f8d22ca5a9820507f154014",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zrajna/lipsia",
"max_stars_repo_path": "src/ted/vted/Histogram.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-18T10:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-10T16:33:42.000Z",
"num_tokens": 722,
"size": 2296
} |
/**
*
* @file qwrapper_dgemm.c
*
* PLASMA core_blas quark wrapper
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Hatem Ltaief
* @author Mathieu Faverge
* @author Jakub Kurzak
* @date 2010-11-15
* @generated d Tue Jan 7 11:44:56 2014
*
**/
#include <cblas.h>
#include "common.h"
/***************************************************************************//**
*
**/
void QUARK_CORE_dgemm(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum transA, int transB,
int m, int n, int k, int nb,
double alpha, const double *A, int lda,
const double *B, int ldb,
double beta, double *C, int ldc)
{
DAG_CORE_GEMM;
QUARK_Insert_Task(quark, CORE_dgemm_quark, task_flags,
sizeof(PLASMA_enum), &transA, VALUE,
sizeof(PLASMA_enum), &transB, VALUE,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(int), &k, VALUE,
sizeof(double), &alpha, VALUE,
sizeof(double)*nb*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(double)*nb*nb, B, INPUT,
sizeof(int), &ldb, VALUE,
sizeof(double), &beta, VALUE,
sizeof(double)*nb*nb, C, INOUT,
sizeof(int), &ldc, VALUE,
0);
}
/***************************************************************************//**
*
**/
void QUARK_CORE_dgemm2( Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum transA, int transB,
int m, int n, int k, int nb,
double alpha, const double *A, int lda,
const double *B, int ldb,
double beta, double *C, int ldc)
{
DAG_CORE_GEMM;
QUARK_Insert_Task(quark, CORE_dgemm_quark, task_flags,
sizeof(PLASMA_enum), &transA, VALUE,
sizeof(PLASMA_enum), &transB, VALUE,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(int), &k, VALUE,
sizeof(double), &alpha, VALUE,
sizeof(double)*nb*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(double)*nb*nb, B, INPUT,
sizeof(int), &ldb, VALUE,
sizeof(double), &beta, VALUE,
sizeof(double)*nb*nb, C, INOUT | LOCALITY | GATHERV,
sizeof(int), &ldc, VALUE,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_dgemm_quark = PCORE_dgemm_quark
#define CORE_dgemm_quark PCORE_dgemm_quark
#endif
void CORE_dgemm_quark(Quark *quark)
{
PLASMA_enum transA;
PLASMA_enum transB;
int m;
int n;
int k;
double alpha;
double *A;
int lda;
double *B;
int ldb;
double beta;
double *C;
int ldc;
quark_unpack_args_13(quark, transA, transB, m, n, k, alpha, A, lda, B, ldb, beta, C, ldc);
cblas_dgemm(
CblasColMajor,
(CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB,
m, n, k,
(alpha), A, lda,
B, ldb,
(beta), C, ldc);
}
/***************************************************************************//**
*
**/
void QUARK_CORE_dgemm_f2(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum transA, int transB,
int m, int n, int k, int nb,
double alpha, const double *A, int lda,
const double *B, int ldb,
double beta, double *C, int ldc,
double *fake1, int szefake1, int flag1,
double *fake2, int szefake2, int flag2)
{
DAG_CORE_GEMM;
QUARK_Insert_Task(quark, CORE_dgemm_f2_quark, task_flags,
sizeof(PLASMA_enum), &transA, VALUE,
sizeof(PLASMA_enum), &transB, VALUE,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(int), &k, VALUE,
sizeof(double), &alpha, VALUE,
sizeof(double)*nb*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(double)*nb*nb, B, INPUT,
sizeof(int), &ldb, VALUE,
sizeof(double), &beta, VALUE,
sizeof(double)*nb*nb, C, INOUT | LOCALITY,
sizeof(int), &ldc, VALUE,
sizeof(double)*szefake1, fake1, flag1,
sizeof(double)*szefake2, fake2, flag2,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_dgemm_f2_quark = PCORE_dgemm_f2_quark
#define CORE_dgemm_f2_quark PCORE_dgemm_f2_quark
#endif
void CORE_dgemm_f2_quark(Quark* quark)
{
PLASMA_enum transA;
PLASMA_enum transB;
int M;
int N;
int K;
double alpha;
double *A;
int LDA;
double *B;
int LDB;
double beta;
double *C;
int LDC;
void *fake1, *fake2;
quark_unpack_args_15(quark, transA, transB, M, N, K, alpha,
A, LDA, B, LDB, beta, C, LDC, fake1, fake2);
cblas_dgemm(
CblasColMajor,
(CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB,
M, N, K,
(alpha), A, LDA,
B, LDB,
(beta), C, LDC);
}
/***************************************************************************//**
*
**/
void QUARK_CORE_dgemm_p2(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum transA, int transB,
int m, int n, int k, int nb,
double alpha, const double *A, int lda,
const double **B, int ldb,
double beta, double *C, int ldc)
{
DAG_CORE_GEMM;
QUARK_Insert_Task(quark, CORE_dgemm_p2_quark, task_flags,
sizeof(PLASMA_enum), &transA, VALUE,
sizeof(PLASMA_enum), &transB, VALUE,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(int), &k, VALUE,
sizeof(double), &alpha, VALUE,
sizeof(double)*lda*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(double*), B, INPUT,
sizeof(int), &ldb, VALUE,
sizeof(double), &beta, VALUE,
sizeof(double)*ldc*nb, C, INOUT | LOCALITY,
sizeof(int), &ldc, VALUE,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_dgemm_p2_quark = PCORE_dgemm_p2_quark
#define CORE_dgemm_p2_quark PCORE_dgemm_p2_quark
#endif
void CORE_dgemm_p2_quark(Quark* quark)
{
PLASMA_enum transA;
PLASMA_enum transB;
int M;
int N;
int K;
double alpha;
double *A;
int LDA;
double **B;
int LDB;
double beta;
double *C;
int LDC;
quark_unpack_args_13(quark, transA, transB, M, N, K, alpha,
A, LDA, B, LDB, beta, C, LDC);
cblas_dgemm(
CblasColMajor,
(CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB,
M, N, K,
(alpha), A, LDA,
*B, LDB,
(beta), C, LDC);
}
/***************************************************************************//**
*
**/
void QUARK_CORE_dgemm_p3(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum transA, int transB,
int m, int n, int k, int nb,
double alpha, const double *A, int lda,
const double *B, int ldb,
double beta, double **C, int ldc)
{
DAG_CORE_GEMM;
QUARK_Insert_Task(quark, CORE_dgemm_p3_quark, task_flags,
sizeof(PLASMA_enum), &transA, VALUE,
sizeof(PLASMA_enum), &transB, VALUE,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(int), &k, VALUE,
sizeof(double), &alpha, VALUE,
sizeof(double)*lda*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(double)*ldb*nb, B, INPUT,
sizeof(int), &ldb, VALUE,
sizeof(double), &beta, VALUE,
sizeof(double*), C, INOUT | LOCALITY,
sizeof(int), &ldc, VALUE,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_dgemm_p3_quark = PCORE_dgemm_p3_quark
#define CORE_dgemm_p3_quark PCORE_dgemm_p3_quark
#endif
void CORE_dgemm_p3_quark(Quark* quark)
{
PLASMA_enum transA;
PLASMA_enum transB;
int M;
int N;
int K;
double alpha;
double *A;
int LDA;
double *B;
int LDB;
double beta;
double **C;
int LDC;
quark_unpack_args_13(quark, transA, transB, M, N, K, alpha,
A, LDA, B, LDB, beta, C, LDC);
cblas_dgemm(
CblasColMajor,
(CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB,
M, N, K,
(alpha), A, LDA,
B, LDB,
(beta), *C, LDC);
}
/***************************************************************************//**
*
**/
void QUARK_CORE_dgemm_p2f1(Quark *quark, Quark_Task_Flags *task_flags,
PLASMA_enum transA, int transB,
int m, int n, int k, int nb,
double alpha, const double *A, int lda,
const double **B, int ldb,
double beta, double *C, int ldc,
double *fake1, int szefake1, int flag1)
{
DAG_CORE_GEMM;
QUARK_Insert_Task(quark, CORE_dgemm_p2f1_quark, task_flags,
sizeof(PLASMA_enum), &transA, VALUE,
sizeof(PLASMA_enum), &transB, VALUE,
sizeof(int), &m, VALUE,
sizeof(int), &n, VALUE,
sizeof(int), &k, VALUE,
sizeof(double), &alpha, VALUE,
sizeof(double)*lda*nb, A, INPUT,
sizeof(int), &lda, VALUE,
sizeof(double*), B, INPUT,
sizeof(int), &ldb, VALUE,
sizeof(double), &beta, VALUE,
sizeof(double)*ldc*nb, C, INOUT | LOCALITY,
sizeof(int), &ldc, VALUE,
sizeof(double)*szefake1, fake1, flag1,
0);
}
/***************************************************************************//**
*
**/
#if defined(PLASMA_HAVE_WEAK)
#pragma weak CORE_dgemm_p2f1_quark = PCORE_dgemm_p2f1_quark
#define CORE_dgemm_p2f1_quark PCORE_dgemm_p2f1_quark
#endif
void CORE_dgemm_p2f1_quark(Quark* quark)
{
PLASMA_enum transA;
PLASMA_enum transB;
int M;
int N;
int K;
double alpha;
double *A;
int LDA;
double **B;
int LDB;
double beta;
double *C;
int LDC;
void *fake1;
quark_unpack_args_14(quark, transA, transB, M, N, K, alpha,
A, LDA, B, LDB, beta, C, LDC, fake1);
cblas_dgemm(
CblasColMajor,
(CBLAS_TRANSPOSE)transA, (CBLAS_TRANSPOSE)transB,
M, N, K,
(alpha), A, LDA,
*B, LDB,
(beta), C, LDC);
}
| {
"alphanum_fraction": 0.4370689655,
"avg_line_length": 35.0549450549,
"ext": "c",
"hexsha": "fd4c4d16c15a6e8843376fd64af46314b1026d90",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zhuangsc/Plasma-ompss1",
"max_forks_repo_path": "core_blas-qwrapper/qwrapper_dgemm.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zhuangsc/Plasma-ompss1",
"max_issues_repo_path": "core_blas-qwrapper/qwrapper_dgemm.c",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zhuangsc/Plasma-ompss1",
"max_stars_repo_path": "core_blas-qwrapper/qwrapper_dgemm.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3203,
"size": 12760
} |
/**
*
* @file testing_cher2k.c
*
* PLASMA testing routines
* PLASMA is a software package provided by Univ. of Tennessee,
* Univ. of California Berkeley and Univ. of Colorado Denver
*
* @version 2.6.0
* @author Mathieu Faverge
* @date 2010-11-15
* @generated c Tue Jan 7 11:45:19 2014
*
**/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <plasma.h>
#include <cblas.h>
#include <lapacke.h>
#include <core_blas.h>
#include "testing_cmain.h"
static int check_solution(PLASMA_enum uplo, PLASMA_enum trans, int N, int K,
PLASMA_Complex32_t alpha, PLASMA_Complex32_t *A, int LDA,
PLASMA_Complex32_t *B, int LDB,
float beta, PLASMA_Complex32_t *Cref, PLASMA_Complex32_t *Cplasma, int LDC);
int testing_cher2k(int argc, char **argv)
{
/* Check for number of arguments*/
if ( argc != 7 ){
USAGE("HER2K", "alpha beta M N LDA LDB LDC",
" - alpha : alpha coefficient\n"
" - beta : beta coefficient\n"
" - N : number of columns and rows of matrix C and number of row of matrix A and B\n"
" - K : number of columns of matrix A and B\n"
" - LDA : leading dimension of matrix A\n"
" - LDB : leading dimension of matrix B\n"
" - LDC : leading dimension of matrix C\n");
return -1;
}
PLASMA_Complex32_t alpha = (PLASMA_Complex32_t) atol(argv[0]);
float beta = (float) atol(argv[1]);
int N = atoi(argv[2]);
int K = atoi(argv[3]);
int LDA = atoi(argv[4]);
int LDB = atoi(argv[5]);
int LDC = atoi(argv[6]);
int NKmax = max(N, K);
float eps;
int info_solution;
int u, t;
size_t LDAxK = LDA*NKmax;
size_t LDBxK = LDB*NKmax;
size_t LDCxN = LDC*N;
PLASMA_Complex32_t *A = (PLASMA_Complex32_t *)malloc(LDAxK*sizeof(PLASMA_Complex32_t));
PLASMA_Complex32_t *B = (PLASMA_Complex32_t *)malloc(LDBxK*sizeof(PLASMA_Complex32_t));
PLASMA_Complex32_t *C = (PLASMA_Complex32_t *)malloc(LDCxN*sizeof(PLASMA_Complex32_t));
PLASMA_Complex32_t *Cinit = (PLASMA_Complex32_t *)malloc(LDCxN*sizeof(PLASMA_Complex32_t));
PLASMA_Complex32_t *Cfinal = (PLASMA_Complex32_t *)malloc(LDCxN*sizeof(PLASMA_Complex32_t));
/* Check if unable to allocate memory */
if ( (!A) || (!B) || (!Cinit) || (!Cfinal) ){
printf("Out of Memory \n ");
return -2;
}
eps = LAPACKE_slamch_work('e');
printf("\n");
printf("------ TESTS FOR PLASMA CHER2K ROUTINE ------- \n");
printf(" Size of the Matrix C %d by %d\n", N, K);
printf("\n");
printf(" The matrix A is randomly generated for each test.\n");
printf("============\n");
printf(" The relative machine precision (eps) is to be %e \n",eps);
printf(" Computational tests pass if scaled residuals are less than 10.\n");
/*----------------------------------------------------------
* TESTING CHER2K
*/
/* Initialize A,B */
LAPACKE_clarnv_work(IONE, ISEED, LDAxK, A);
LAPACKE_clarnv_work(IONE, ISEED, LDBxK, B);
/* Initialize C */
PLASMA_cplghe( (float)0., N, C, LDC, 51 );
for (u=0; u<2; u++) {
for (t=0; t<3; t++) {
if (trans[t] == PlasmaTrans) continue;
memcpy(Cinit, C, LDCxN*sizeof(PLASMA_Complex32_t));
memcpy(Cfinal, C, LDCxN*sizeof(PLASMA_Complex32_t));
/* PLASMA CHER2K */
PLASMA_cher2k(uplo[u], trans[t], N, K, alpha, A, LDA, B, LDB, beta, Cfinal, LDC);
/* Check the solution */
info_solution = check_solution(uplo[u], trans[t], N, K,
alpha, A, LDA, B, LDB, beta, Cinit, Cfinal, LDC);
if (info_solution == 0) {
printf("***************************************************\n");
printf(" ---- TESTING CHER2K (%5s, %s) ........... PASSED !\n", uplostr[u], transstr[t]);
printf("***************************************************\n");
}
else {
printf("************************************************\n");
printf(" - TESTING CHER2K (%5s, %s) ... FAILED !\n", uplostr[u], transstr[t]);
printf("************************************************\n");
}
}
}
free(A); free(B); free(C);
free(Cinit); free(Cfinal);
return 0;
}
/*--------------------------------------------------------------
* Check the solution
*/
static int check_solution(PLASMA_enum uplo, PLASMA_enum trans, int N, int K,
PLASMA_Complex32_t alpha, PLASMA_Complex32_t *A, int LDA,
PLASMA_Complex32_t *B, int LDB,
float beta, PLASMA_Complex32_t *Cref, PLASMA_Complex32_t *Cplasma, int LDC)
{
int info_solution;
float Anorm, Bnorm, Cinitnorm, Cplasmanorm, Clapacknorm, Rnorm, result;
float eps;
PLASMA_Complex32_t beta_const;
float *work = (float *)malloc(max(N, K)* sizeof(float));
beta_const = -1.0;
Anorm = LAPACKE_clange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm),
(trans == PlasmaNoTrans) ? N : K,
(trans == PlasmaNoTrans) ? K : N, A, LDA, work);
Bnorm = LAPACKE_clange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm),
(trans == PlasmaNoTrans) ? N : K,
(trans == PlasmaNoTrans) ? K : N, B, LDB, work);
Cinitnorm = LAPACKE_clange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), N, N, Cref, LDC, work);
Cplasmanorm = LAPACKE_clange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), N, N, Cplasma, LDC, work);
cblas_cher2k(CblasColMajor, (CBLAS_UPLO)uplo, (CBLAS_TRANSPOSE)trans,
N, K, CBLAS_SADDR(alpha), A, LDA, B, LDB, (beta), Cref, LDC);
Clapacknorm = LAPACKE_clange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), N, N, Cref, LDC, work);
cblas_caxpy(LDC*N, CBLAS_SADDR(beta_const), Cplasma, 1, Cref, 1);
Rnorm = LAPACKE_clange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), N, N, Cref, LDC, work);
eps = LAPACKE_slamch_work('e');
printf("Rnorm %e, Anorm %e, Cinitnorm %e, Cplasmanorm %e, Clapacknorm %e\n",
Rnorm, Anorm, Cinitnorm, Cplasmanorm, Clapacknorm);
result = Rnorm / ((Anorm + Bnorm + Cinitnorm) * N * eps);
printf("============\n");
printf("Checking the norm of the difference against reference CHER2K \n");
printf("-- ||Cplasma - Clapack||_oo/((||A||_oo+||C||_oo).N.eps) = %e \n", result);
if ( isnan(Rnorm) || isinf(Rnorm) || isnan(result) || isinf(result) || (result > 10.0) ) {
printf("-- The solution is suspicious ! \n");
info_solution = 1;
}
else {
printf("-- The solution is CORRECT ! \n");
info_solution= 0 ;
}
free(work);
return info_solution;
}
| {
"alphanum_fraction": 0.5447017544,
"avg_line_length": 37.8989361702,
"ext": "c",
"hexsha": "d2b00e8163bd4de975b08aa2af6fb909586abf1b",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zhuangsc/Plasma-ompss1",
"max_forks_repo_path": "testing/testing_cher2k.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "zhuangsc/Plasma-ompss1",
"max_issues_repo_path": "testing/testing_cher2k.c",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bcc99c164a256bc7df7c936b9c43afd38c12aea2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zhuangsc/Plasma-ompss1",
"max_stars_repo_path": "testing/testing_cher2k.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2131,
"size": 7125
} |
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <gsl/gsl_interp.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_errno.h>
#include "ccl.h"
ccl_f2d_t *ccl_f2d_t_copy(ccl_f2d_t *f2d_o, int *status)
{
int s2dstatus=0;
ccl_f2d_t *f2d = malloc(sizeof(ccl_f2d_t));
if (f2d == NULL)
*status = CCL_ERROR_MEMORY;
if(*status==0) {
f2d->lkmin = f2d_o->lkmin;
f2d->lkmax = f2d_o->lkmax;
f2d->amin = f2d_o->amin;
f2d->amax = f2d_o->amax;
f2d->is_factorizable = f2d_o->is_factorizable;
f2d->is_k_constant = f2d_o->is_k_constant;
f2d->is_a_constant = f2d_o->is_a_constant;
f2d->extrap_linear_growth = f2d_o->extrap_linear_growth;
f2d->extrap_order_lok = f2d_o->extrap_order_lok;
f2d->extrap_order_hik = f2d_o->extrap_order_hik;
f2d->is_log = f2d_o->is_log;
f2d->growth = f2d_o->growth;
f2d->growth_factor_0 = f2d_o->growth_factor_0;
f2d->growth_exponent = f2d_o->growth_exponent;
if(f2d_o->fk != NULL) {
f2d->fk = gsl_spline_alloc(gsl_interp_cspline,
f2d_o->fk->size);
if(f2d->fk == NULL)
*status = CCL_ERROR_MEMORY;
if(*status==0) {
s2dstatus |= gsl_spline_init(f2d->fk, f2d_o->fk->x,
f2d_o->fk->y, f2d_o->fk->size);
if(s2dstatus)
*status = CCL_ERROR_SPLINE;
}
}
else
f2d->fk = NULL;
}
if(*status==0) {
if(f2d_o->fa != NULL) {
f2d->fa = gsl_spline_alloc(gsl_interp_cspline,
f2d_o->fa->size);
if(f2d->fa == NULL)
*status = CCL_ERROR_MEMORY;
if(*status==0) {
s2dstatus |= gsl_spline_init(f2d->fa, f2d_o->fa->x,
f2d_o->fa->y, f2d_o->fa->size);
if(s2dstatus)
*status = CCL_ERROR_SPLINE;
}
}
else
f2d->fa = NULL;
}
if(*status==0) {
if(f2d_o->fka != NULL) {
f2d->fka = gsl_spline2d_alloc(gsl_interp2d_bicubic,
f2d_o->fka->interp_object.xsize,
f2d_o->fka->interp_object.ysize);
if(f2d->fka == NULL)
*status = CCL_ERROR_MEMORY;
if(*status==0) {
s2dstatus |= gsl_spline2d_init(f2d->fka, f2d_o->fka->xarr,
f2d_o->fka->yarr, f2d_o->fka->zarr,
f2d_o->fka->interp_object.xsize,
f2d_o->fka->interp_object.ysize);
if(s2dstatus)
*status = CCL_ERROR_SPLINE;
}
}
else
f2d->fka = NULL;
}
return f2d;
}
ccl_f2d_t *ccl_f2d_t_new(int na,double *a_arr,
int nk,double *lk_arr,
double *fka_arr,
double *fk_arr,
double *fa_arr,
int is_factorizable,
int extrap_order_lok,
int extrap_order_hik,
ccl_f2d_extrap_growth_t extrap_linear_growth,
int is_fka_log,
double (*growth)(double),
double growth_factor_0,
int growth_exponent,
ccl_f2d_interp_t interp_type,
int *status) {
int s2dstatus=0;
ccl_f2d_t *f2d = malloc(sizeof(ccl_f2d_t));
if (f2d == NULL)
*status = CCL_ERROR_MEMORY;
if (*status == 0) {
is_factorizable = is_factorizable || (a_arr == NULL) || (lk_arr == NULL) || (fka_arr == NULL);
f2d->is_factorizable = is_factorizable;
f2d->is_k_constant = ((lk_arr == NULL) || ((fka_arr == NULL) && (fk_arr == NULL)));
f2d->is_a_constant = ((a_arr == NULL) || ((fka_arr == NULL) && (fa_arr == NULL)));
f2d->extrap_order_lok = extrap_order_lok;
f2d->extrap_order_hik = extrap_order_hik;
f2d->extrap_linear_growth = extrap_linear_growth;
f2d->is_log = is_fka_log;
f2d->growth = growth;
f2d->growth_factor_0 = growth_factor_0;
f2d->growth_exponent = growth_exponent;
f2d->fka = NULL;
f2d->fk = NULL;
f2d->fa = NULL;
if (!(f2d->is_k_constant)) { //If it's not constant
f2d->lkmin = lk_arr[0];
f2d->lkmax = lk_arr[nk-1];
}
if (!(f2d->is_a_constant)) {
f2d->amin = a_arr[0];
f2d->amax = a_arr[na-1];
}
}
if ((extrap_order_lok > 2) || (extrap_order_lok < 0) || (extrap_order_hik > 2) || (extrap_order_hik < 0))
*status = CCL_ERROR_INCONSISTENT;
if ((extrap_linear_growth != ccl_f2d_cclgrowth) &&
(extrap_linear_growth != ccl_f2d_customgrowth) &&
(extrap_linear_growth != ccl_f2d_constantgrowth) &&
(extrap_linear_growth != ccl_f2d_no_extrapol))
*status = CCL_ERROR_INCONSISTENT;
if(*status == 0) {
switch(interp_type) {
case(ccl_f2d_3):
if (f2d->is_factorizable) {
// Do not allocate spline if constant
if(f2d->is_k_constant)
f2d->fk = NULL;
else { //Otherwise allocate and check
f2d->fk = gsl_spline_alloc(gsl_interp_cspline, nk);
if(f2d->fk == NULL)
*status = CCL_ERROR_MEMORY;
}
// Do not allocate spline if constant
if (f2d->is_a_constant)
f2d->fa = NULL;
else { //Otherwise allocate and check
f2d->fa = gsl_spline_alloc(gsl_interp_cspline, na);
if (f2d->fa == NULL)
*status = CCL_ERROR_MEMORY;
}
}
else {
// Do not allocate spline if constant
if ((f2d->is_k_constant) || (f2d->is_a_constant))
f2d->fka = NULL;
else { //Otherwise allocate and check
f2d->fka = gsl_spline2d_alloc(gsl_interp2d_bicubic, nk, na);
if (f2d->fka == NULL)
*status = CCL_ERROR_MEMORY;
}
}
break;
default:
f2d->fk = NULL;
f2d->fa = NULL;
f2d->fka = NULL;
}
}
if (*status == 0) {
if (f2d->is_factorizable) {
if (f2d->fk != NULL)
s2dstatus |= gsl_spline_init(f2d->fk, lk_arr, fk_arr, nk);
if (f2d->fa != NULL)
s2dstatus |= gsl_spline_init(f2d->fa, a_arr, fa_arr, na);
}
else {
if (f2d->fka != NULL)
s2dstatus=gsl_spline2d_init(f2d->fka, lk_arr, a_arr, fka_arr, nk, na);
}
if (s2dstatus)
*status = CCL_ERROR_SPLINE;
}
return f2d;
}
double ccl_f2d_t_eval(ccl_f2d_t *f2d,double lk,double a,void *cosmo, int *status) {
int is_hiz, is_loz;
double a_ev = a;
if (f2d->is_a_constant) {
is_hiz = 0;
is_loz = 0;
}
else {
is_hiz = a < f2d->amin;
is_loz = a > f2d->amax;
if (is_loz) { // Are we above the interpolation range in a?
if (f2d->extrap_linear_growth == ccl_f2d_no_extrapol) {
*status=CCL_ERROR_SPLINE_EV;
return NAN;
}
a_ev = f2d->amax;
}
else if (is_hiz) { // Are we below the interpolation range in a?
if (f2d->extrap_linear_growth == ccl_f2d_no_extrapol) {
*status=CCL_ERROR_SPLINE_EV;
return NAN;
}
a_ev = f2d->amin;
}
}
int is_hik, is_lok;
double fka_pre, fka_post;
double lk_ev = lk;
if (f2d->is_k_constant) {
is_hik = 0;
is_lok = 0;
}
else {
is_hik = lk > f2d->lkmax;
is_lok = lk < f2d->lkmin;
if (is_hik) // Are we above the interpolation range in k?
lk_ev = f2d->lkmax;
else if (is_lok) // Are we below the interpolation range in k?
lk_ev = f2d->lkmin;
}
// Evaluate spline
int spstatus=0;
if (f2d->is_factorizable) {
double fk, fa;
if (f2d->fk == NULL) {
if (f2d->is_log)
fk = 0;
else
fk = 1;
}
else
spstatus |= gsl_spline_eval_e(f2d->fk, lk_ev, NULL, &fk);
if (f2d->fa == NULL) {
if (f2d->is_log)
fa = 0;
else
fa = 1;
}
else
spstatus |= gsl_spline_eval_e(f2d->fa, a_ev, NULL, &fa);
if (f2d->is_log)
fka_pre = fk+fa;
else
fka_pre = fk*fa;
}
else {
if (f2d->fka == NULL) {
if (f2d->is_log)
fka_pre = 0;
else
fka_pre = 1;
}
else
spstatus = gsl_spline2d_eval_e(f2d->fka, lk_ev, a_ev, NULL, NULL, &fka_pre);
}
if (spstatus) {
*status = CCL_ERROR_SPLINE_EV;
return NAN;
}
// Now extrapolate in k if needed
if (is_hik) {
fka_post = fka_pre;
if (f2d->extrap_order_hik > 0) {
double pd;
double dlk = lk-lk_ev;
if (f2d->is_factorizable)
spstatus = gsl_spline_eval_deriv_e(f2d->fk, lk_ev, NULL, &pd);
else
spstatus = gsl_spline2d_eval_deriv_x_e(f2d->fka, lk_ev, a_ev, NULL, NULL, &pd);
if (spstatus) {
*status = CCL_ERROR_SPLINE_EV;
return NAN;
}
fka_post += pd*dlk;
if (f2d->extrap_order_hik > 1) {
if (f2d->is_factorizable)
spstatus = gsl_spline_eval_deriv2_e(f2d->fk, lk_ev, NULL, &pd);
else
spstatus = gsl_spline2d_eval_deriv_xx_e(f2d->fka, lk_ev, a_ev, NULL, NULL, &pd);
if (spstatus) {
*status=CCL_ERROR_SPLINE_EV;
return NAN;
}
fka_post += pd*dlk*dlk*0.5;
}
}
}
else if (is_lok) {
fka_post = fka_pre;
if (f2d->extrap_order_lok > 0) {
double pd;
double dlk = lk-lk_ev;
if (f2d->is_factorizable)
spstatus = gsl_spline_eval_deriv_e(f2d->fk, lk_ev, NULL, &pd);
else
spstatus = gsl_spline2d_eval_deriv_x_e(f2d->fka, lk_ev, a_ev, NULL, NULL, &pd);
if (spstatus) {
*status = CCL_ERROR_SPLINE_EV;
return NAN;
}
fka_post += pd*dlk;
if (f2d->extrap_order_lok > 1) {
if (f2d->is_factorizable)
spstatus = gsl_spline_eval_deriv2_e(f2d->fk, lk_ev, NULL, &pd);
else
spstatus = gsl_spline2d_eval_deriv_xx_e(f2d->fka, lk_ev, a_ev, NULL, NULL, &pd);
if (spstatus) {
*status = CCL_ERROR_SPLINE_EV;
return NAN;
}
fka_post += pd*dlk*dlk*0.5;
}
}
}
else
fka_post = fka_pre;
// Exponentiate if needed
if (f2d->is_log)
fka_post = exp(fka_post);
// Extrapolate in a if needed
if (is_hiz) {
double gz;
if (f2d->extrap_linear_growth == ccl_f2d_cclgrowth) { // Use CCL's growth function
ccl_cosmology *csm = (ccl_cosmology *)cosmo;
if (!csm->computed_growth) {
*status = CCL_ERROR_GROWTH_INIT;
ccl_cosmology_set_status_message(
csm,
"ccl_f2d.c: ccl_f2d_t_eval(): growth factor splines have not been precomputed!");
return NAN;
}
gz = (
ccl_growth_factor(csm, a, status) /
ccl_growth_factor(csm, a_ev, status));
}
else if (f2d->extrap_linear_growth == ccl_f2d_customgrowth) // Use internal growth function
gz = f2d->growth(a) / f2d->growth(a_ev);
else // Use constant growth factor
gz = f2d->growth_factor_0;
fka_post *= pow(gz, f2d->growth_exponent);
}
return fka_post;
}
void ccl_f2d_t_free(ccl_f2d_t *f2d)
{
if(f2d != NULL) {
if(f2d->fka != NULL)
gsl_spline2d_free(f2d->fka);
if(f2d->fk != NULL)
gsl_spline_free(f2d->fk);
if(f2d->fa != NULL)
gsl_spline_free(f2d->fa);
free(f2d);
}
}
| {
"alphanum_fraction": 0.5573653761,
"avg_line_length": 28.5877862595,
"ext": "c",
"hexsha": "3ea62479b740014c44a5a84ef6c8c17a5d9aac0a",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ddd35e49f9d2968cef3d3bc1bac8b55dbb4cf91",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "borisbolliet/CCL",
"max_forks_repo_path": "src/ccl_f2d.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ddd35e49f9d2968cef3d3bc1bac8b55dbb4cf91",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "borisbolliet/CCL",
"max_issues_repo_path": "src/ccl_f2d.c",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ddd35e49f9d2968cef3d3bc1bac8b55dbb4cf91",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "borisbolliet/CCL",
"max_stars_repo_path": "src/ccl_f2d.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3762,
"size": 11235
} |
/* specfunc/result.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* 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.
*/
/* Author: G. Jungman */
#include <config.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_sf_exp.h>
#include <gsl/gsl_sf_result.h>
int
gsl_sf_result_smash_e(const gsl_sf_result_e10 * re, gsl_sf_result * r)
{
if(re->e10 == 0) {
/* nothing to smash */
r->val = re->val;
r->err = re->err;
return GSL_SUCCESS;
}
else {
const double av = fabs(re->val);
const double ae = fabs(re->err);
if( GSL_SQRT_DBL_MIN < av && av < GSL_SQRT_DBL_MAX
&& GSL_SQRT_DBL_MIN < ae && ae < GSL_SQRT_DBL_MAX
&& 0.49*GSL_LOG_DBL_MIN < re->e10 && re->e10 < 0.49*GSL_LOG_DBL_MAX
) {
const double scale = exp(re->e10 * M_LN10);
r->val = re->val * scale;
r->err = re->err * scale;
return GSL_SUCCESS;
}
else {
return gsl_sf_exp_mult_err_e(re->e10*M_LN10, 0.0, re->val, re->err, r);
}
}
/*
int stat_v;
int stat_e;
if(re->val == 0.0) {
r->val = 0.0;
stat_v = GSL_SUCCESS;
}
else {
gsl_sf_result r_val;
const double s = GSL_SIGN(re->val);
const double x_v = re->e10*M_LN10 + log(fabs(re->val));
stat_v = gsl_sf_exp_e(x_v, &r_val);
r->val = s * r_val.val;
}
if(re->err == 0.0) {
r->err = 0.0;
stat_e = GSL_SUCCESS;
}
else if(re->val != 0.0) {
r->err = fabs(r->val * re->err/re->val);
stat_e = GSL_SUCCESS;
}
else {
gsl_sf_result r_err;
const double x_e = re->e10*M_LN10 + log(fabs(re->err));
stat_e = gsl_sf_exp_e(x_e, &r_err);
r->err = r_err.val;
}
return GSL_ERROR_SELECT_2(stat_v, stat_e);
*/
}
| {
"alphanum_fraction": 0.6330695544,
"avg_line_length": 26.6777777778,
"ext": "c",
"hexsha": "43ff3bb14a4948e3ca54133f0fa5ef62d0f442b9",
"lang": "C",
"max_forks_count": 40,
"max_forks_repo_forks_event_max_datetime": "2022-03-03T23:23:37.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-26T15:31:16.000Z",
"max_forks_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "manggoguy/parsec-modified",
"max_forks_repo_path": "pkgs/libs/gsl/src/specfunc/result.c",
"max_issues_count": 12,
"max_issues_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_issues_repo_issues_event_max_datetime": "2022-03-13T03:54:24.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-12-15T08:30:19.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "manggoguy/parsec-modified",
"max_issues_repo_path": "pkgs/libs/gsl/src/specfunc/result.c",
"max_line_length": 81,
"max_stars_count": 64,
"max_stars_repo_head_hexsha": "d14edfb62795805c84a4280d67b50cca175b95af",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "manggoguy/parsec-modified",
"max_stars_repo_path": "pkgs/libs/gsl/src/specfunc/result.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T13:26:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-06T00:30:56.000Z",
"num_tokens": 769,
"size": 2401
} |
#ifndef TRANS_TYPE
#define TRANS_TYPE
#include <gsl/gsl_vector.h>
// corresponding python variable: element of 'list_n_original_diff'
typedef struct {
gsl_vector *inc1;
gsl_vector *inc2;
gsl_vector *skp1;
gsl_vector *skp2;
int inclu_len;
int skip_len;
int flag;
char* id;
} odiff;
typedef struct {
int batch_size;
void **datum;
} batch_datum;
// used to represent the reture value of
// MLE_marginal_iteration and MLE_marginal_iteration_constrain.
// corresponding python variable: '[current_sum,[psi1,psi2,beta_0,beta_1,var1,var2]]'
typedef struct {
double sum;
struct {
gsl_vector *psi1;
gsl_vector *psi2;
double beta0;
double beta1;
double var1;
double var2;
} params;
} mle_result;
// we use a linked list to represent a python list.
// corresponding python variable: 'list_n_original_diff'
typedef struct dnode{
odiff* data;
struct dnode* next;
struct dnode* end;
} diff_list_node;
typedef struct node {
void* data;
struct node* next;
struct node* end;
} list_node;
// we use fortran l_bfgs_b routine to solve the numerical optimization problem.
// (i.e. f = 0.0 at the optimal solution.)
// only the minimal intersection of C's and Fortran's many data types can be relied on:
// the following are some essential mapping between c type and fortran type
// counterpart of f2c.h
typedef int integer;
typedef float real;
typedef double doublereal;
typedef long int logical;
#endif
| {
"alphanum_fraction": 0.7003942181,
"avg_line_length": 21.7428571429,
"ext": "h",
"hexsha": "af71f58aa52421122288c759c625d6cb06e79521",
"lang": "C",
"max_forks_count": 39,
"max_forks_repo_forks_event_max_datetime": "2022-03-19T09:14:46.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-06-01T20:25:44.000Z",
"max_forks_repo_head_hexsha": "8a2ad659717a1ccd6dbecd593dc1370ba7c30621",
"max_forks_repo_licenses": [
"BSD-2-Clause-FreeBSD"
],
"max_forks_repo_name": "chunjie-sam-liu/rmats-turbo",
"max_forks_repo_path": "rMATS_C/include/type.h",
"max_issues_count": 163,
"max_issues_repo_head_hexsha": "8a2ad659717a1ccd6dbecd593dc1370ba7c30621",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T19:39:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-06-03T06:54:27.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause-FreeBSD"
],
"max_issues_repo_name": "chunjie-sam-liu/rmats-turbo",
"max_issues_repo_path": "rMATS_C/include/type.h",
"max_line_length": 87,
"max_stars_count": 88,
"max_stars_repo_head_hexsha": "8a2ad659717a1ccd6dbecd593dc1370ba7c30621",
"max_stars_repo_licenses": [
"BSD-2-Clause-FreeBSD"
],
"max_stars_repo_name": "chunjie-sam-liu/rmats-turbo",
"max_stars_repo_path": "rMATS_C/include/type.h",
"max_stars_repo_stars_event_max_datetime": "2022-03-18T17:34:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-06-01T20:20:01.000Z",
"num_tokens": 389,
"size": 1522
} |
#include <sstream>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_linalg.h>
#include <gsl/gsl_cblas.h>
// pretty print
std::string ppMatrix(const gsl_matrix *m) {
std::ostringstream str;
int r, c;
str << "";
for (r = 0; r < (int) m->size1; r++) {
for (c = 0; c < (int) m->size2; c++) {
str << gsl_matrix_get(m, r, c);
if (c < m->size2 - 1) {
str << " ";
}
}
str << "\n";
}
return str.str();
}
void
matrixInverseCheck() {
// Define the dimension n of the matrix
// and the signum s (for LU decomposition)
int n = 2;
int s;
// Define all the used matrices
gsl_matrix * m = gsl_matrix_alloc (n, n);
gsl_matrix * inverse = gsl_matrix_alloc (n, n);
gsl_permutation * perm = gsl_permutation_alloc (n);
// Fill the matrix m
gsl_matrix_set (m, 0, 0, 0.378589);
gsl_matrix_set (m, 0, 1, 0.971711);
gsl_matrix_set (m, 0, 2, 0.016087);
gsl_matrix_set (m, 0, 3, 0.037668);
gsl_matrix_set (m, 0, 4, 0.312398);
gsl_matrix_set (m, 1, 0, 0.756377);
gsl_matrix_set (m, 1, 1, 0.345708);
gsl_matrix_set (m, 1, 2, 0.922947);
gsl_matrix_set (m, 1, 3, 0.846671);
gsl_matrix_set (m, 1, 4, 0.856103);
gsl_matrix_set (m, 2, 0, 0.732510);
gsl_matrix_set (m, 2, 1, 0.108942);
gsl_matrix_set (m, 2, 2, 0.476969);
gsl_matrix_set (m, 2, 3, 0.398254);
gsl_matrix_set (m, 2, 4, 0.507045);
gsl_matrix_set (m, 3, 0, 0.162608);
gsl_matrix_set (m, 3, 1, 0.227770);
gsl_matrix_set (m, 3, 2, 0.533074);
gsl_matrix_set (m, 3, 3, 0.807075);
gsl_matrix_set (m, 3, 4, 0.180335);
gsl_matrix_set (m, 4, 0, 0.517006);
gsl_matrix_set (m, 4, 1, 0.315992);
gsl_matrix_set (m, 4, 2, 0.914848);
gsl_matrix_set (m, 4, 3, 0.460825);
gsl_matrix_set (m, 4, 4, 0.731980);
// Make LU decomposition of matrix m
gsl_linalg_LU_decomp (m, perm, &s);
// Invert the matrix m
gsl_linalg_LU_invert (m, perm, inverse);
}
void
matrixOpsCheck() {
fprintf(stdout, "\n Matrix Operations ..............................................\n");
int L = 3, M = 3;
int i, j;
gsl_matrix *m = gsl_matrix_alloc(L, M);
for (i = 0; i < L; i++)
for (j = 0; j < M; j++)
gsl_matrix_set(m, i, j, 0.23 + 100 * i + j);
fprintf(stdout, "m = %s\n", ppMatrix(m).c_str());
gsl_matrix_free(m);
fprintf(stdout, "\n");
}
int
main(void) {
matrixOpsCheck();
return 0;
}
| {
"alphanum_fraction": 0.5404984424,
"avg_line_length": 25.68,
"ext": "c",
"hexsha": "4ce461b1985108cb5080050e22b00e25633e0f2b",
"lang": "C",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "eb61e93de15a98c34239a938d49459080e324ba9",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "anthonyohare/SwiftScientificLibrary",
"max_forks_repo_path": "ValidationTests/gsl_matrix_tests.c",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eb61e93de15a98c34239a938d49459080e324ba9",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "anthonyohare/SwiftScientificLibrary",
"max_issues_repo_path": "ValidationTests/gsl_matrix_tests.c",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eb61e93de15a98c34239a938d49459080e324ba9",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "anthonyohare/SwiftScientificLibrary",
"max_stars_repo_path": "ValidationTests/gsl_matrix_tests.c",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 929,
"size": 2568
} |
/*
Copyright (c) 2011-2013, UT-Battelle, LLC
All rights reserved
[PsimagLite, Version 1.0.0]
[by G.A., Oak Ridge National Laboratory]
UT Battelle Open Source Software License 11242008
OPEN SOURCE LICENSE
Subject to the conditions of this License, each
contributor to this software hereby grants, free of
charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), a
perpetual, worldwide, non-exclusive, no-charge,
royalty-free, irrevocable copyright license to use, copy,
modify, merge, publish, distribute, and/or sublicense
copies of the Software.
1. Redistributions of Software must retain the above
copyright and license notices, this list of conditions,
and the following disclaimer. Changes or modifications
to, or derivative works of, the Software should be noted
with comments and the contributor and organization's
name.
2. Neither the names of UT-Battelle, LLC or the
Department of Energy nor the names of the Software
contributors may be used to endorse or promote products
derived from this software without specific prior written
permission of UT-Battelle.
3. The software and the end-user documentation included
with the redistribution, with or without modification,
must include the following acknowledgment:
"This product includes software produced by UT-Battelle,
LLC under Contract No. DE-AC05-00OR22725 with the
Department of Energy."
*********************************************************
DISCLAIMER
THE SOFTWARE IS SUPPLIED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER, CONTRIBUTORS, UNITED STATES GOVERNMENT,
OR THE UNITED STATES DEPARTMENT OF ENERGY BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
NEITHER THE UNITED STATES GOVERNMENT, NOR THE UNITED
STATES DEPARTMENT OF ENERGY, NOR THE COPYRIGHT OWNER, NOR
ANY OF THEIR EMPLOYEES, REPRESENTS THAT THE USE OF ANY
INFORMATION, DATA, APPARATUS, PRODUCT, OR PROCESS
DISCLOSED WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS.
*********************************************************
*/
/** \ingroup PsimagLite */
/*@{*/
/*! \file GslWrapper.h
*
* Wrapper for GSL functions and types
*/
#ifndef GSL_WRAPPER_H_
#define GSL_WRAPPER_H_
#ifdef USE_GSL
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_sf_result.h>
#include <gsl/gsl_sf_gamma.h>
#include <gsl/gsl_sf_expint.h>
#endif
#include <stdexcept>
#include "Vector.h"
namespace PsimagLite {
#ifndef USE_GSL
class GslWrapper {
public:
typedef int DummyType;
typedef DummyType gsl_integration_workspace;
typedef double (* GslWrapperFunctionType) (double, void * );
typedef struct {
double val;
double err;
} gsl_sf_result;
typedef void (* gsl_error_handler_t) (const char *,const char *,int,int);
struct gsl_function {
GslWrapperFunctionType function;
void * params;
};
gsl_error_handler_t gsl_set_error_handler (gsl_error_handler_t) const
{
thereSnoGsl();
gsl_error_handler_t *fx = new gsl_error_handler_t();
return *fx;
}
gsl_integration_workspace * gsl_integration_workspace_alloc (SizeType) const
{
thereSnoGsl();
int* x = new int;
return x;
}
void gsl_integration_workspace_free (gsl_integration_workspace*) const
{
thereSnoGsl();
}
int gsl_integration_qag(const gsl_function*,
double,
double,
double,
double,
size_t,
int,
gsl_integration_workspace*,
double*,
double*) const
{
thereSnoGsl();
return 0;
}
int gsl_integration_qagiu(gsl_function*,
double,
double,
double,
size_t ,
gsl_integration_workspace*,
double*,
double*) const
{
thereSnoGsl();
return 0;
}
int gsl_integration_qagp (const gsl_function*,
double*,
SizeType,
double,
double,
SizeType,
gsl_integration_workspace*,
double*,
double*) const
{
thereSnoGsl();
return 0;
}
int gsl_integration_qagi(gsl_function*,
double,
double,
size_t,
gsl_integration_workspace*,
double*,
double*) const
{
thereSnoGsl();
return 0;
}
void printError(int) const
{
thereSnoGsl();
}
int gsl_sf_lngamma_complex_e(double,
double,
gsl_sf_result*,
gsl_sf_result*) const
{
thereSnoGsl();
return 0;
}
int gsl_sf_Ci_e(double, gsl_sf_result*)
{
thereSnoGsl();
return 0;
}
private:
void thereSnoGsl() const
{
throw RuntimeError("You need to compile with the GSL\n");
}
}; // class GslWrapper
#else
class GslWrapper {
public:
typedef ::gsl_integration_workspace gsl_integration_workspace;
typedef ::gsl_function gsl_function;
typedef ::gsl_sf_result gsl_sf_result;
void printError(int status) const
{
std::cerr<<"GslWrapper: error: "<<gsl_strerror(status)<<"\n";
}
gsl_error_handler_t * gsl_set_error_handler (gsl_error_handler_t * new_handler) const
{
return ::gsl_set_error_handler(new_handler);
}
gsl_integration_workspace * gsl_integration_workspace_alloc (SizeType n) const
{
return ::gsl_integration_workspace_alloc(n);
}
void gsl_integration_workspace_free (gsl_integration_workspace * w) const
{
return ::gsl_integration_workspace_free(w);
}
int gsl_integration_qagi(gsl_function* f,
double epsabs,
double epsrel,
size_t limit,
gsl_integration_workspace* workspace,
double* result,
double* abserr) const
{
return ::gsl_integration_qagi(f,epsabs,epsrel,limit,workspace,result,abserr);
}
int gsl_integration_qagiu(gsl_function* f,
double a,
double epsabs,
double epsrel,
size_t limit,
gsl_integration_workspace* workspace,
double* result,
double* abserr) const
{
return ::gsl_integration_qagiu(f,a,epsabs,epsrel,limit,workspace,result,abserr);
}
int gsl_integration_qagp (const gsl_function * f,
double * pts,
SizeType npts,
double epsabs,
double epsrel,
SizeType limit,
gsl_integration_workspace * workspace,
double * result,
double * abserr) const
{
return ::gsl_integration_qagp(f,
pts,
npts,
epsabs,
epsrel,
limit,
workspace,
result,
abserr);
}
int gsl_integration_qag(const gsl_function * f,
double a,
double b,
double epsabs,
double epsrel,
size_t limit,
int key,
gsl_integration_workspace* workspace,
double* result,
double* abserr) const
{
return ::gsl_integration_qag(f,
a,
b,
epsabs,
epsrel,
limit,
key,
workspace,
result,
abserr);
}
int gsl_sf_lngamma_complex_e(double zr,
double zi,
gsl_sf_result* lnr,
gsl_sf_result* arg) const
{
return ::gsl_sf_lngamma_complex_e(zr, zi, lnr, arg);
}
int gsl_sf_Ci_e(double x, gsl_sf_result* result) const
{
return ::gsl_sf_Ci_e(x,result);
}
}; // class GslWrapper
#endif
} // namespace PsimagLite
/*@}*/
#endif // GSL_WRAPPER_H_
| {
"alphanum_fraction": 0.5708923209,
"avg_line_length": 27.8328358209,
"ext": "h",
"hexsha": "3163b69288037ee8eeecfa31f9c43667198ea848",
"lang": "C",
"max_forks_count": 5,
"max_forks_repo_forks_event_max_datetime": "2019-11-22T03:33:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-04-29T17:28:00.000Z",
"max_forks_repo_head_hexsha": "ffa0ffad75c5db218a9edea1a9581fed98c2648f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "npatel37/PsimagLiteORNL",
"max_forks_repo_path": "src/GslWrapper.h",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "ffa0ffad75c5db218a9edea1a9581fed98c2648f",
"max_issues_repo_issues_event_max_datetime": "2019-07-08T22:56:12.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-02T20:28:21.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "npatel37/PsimagLiteORNL",
"max_issues_repo_path": "src/GslWrapper.h",
"max_line_length": 86,
"max_stars_count": 8,
"max_stars_repo_head_hexsha": "1cdeb4530c66cd41bd0c59af9ad2ecb1069ca010",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "g1257/PsimagLite",
"max_stars_repo_path": "src/GslWrapper.h",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T02:37:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-19T16:06:52.000Z",
"num_tokens": 1957,
"size": 9324
} |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_interp.h>
#include <gsl/gsl_spline.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_roots.h>
#include "ccl.h"
/*
* We use the remapping procedure in https://arxiv.org/pdf/1601.07230.pdf
* to map w0-wa models onto wa == 0 models.
* The functions below implement this procedure.
*/
// I snuck a private function from background.c into here. :P
// The default routines create a full spline but we just need one value.
// This may seem like over optimizing, but in testing initializing halofit
// is an order of magnitude or more slower if we don't do this.
void compute_chi(double a, ccl_cosmology *cosmo, double * chi, int * stat);
static double zdrag_eh(ccl_parameters *params) {
// eqn 4 of Eisenstein & Hu 1998
double OMh2 = (params->Omega_c + params->Omega_b) * params->h * params->h;
double OBh2 = params->Omega_b * params->h * params->h;
double b1 = 0.313 * pow(OMh2, -0.419) * (1 + 0.607*pow(OMh2, 0.674));
double b2 = 0.238 * pow(OMh2, 0.223);
return 1291 * pow(OMh2, 0.251) * (1 + b1*pow(OBh2, b2)) / (1 + 0.659*pow(OMh2, 0.828));
}
struct hf_model_match_data {
double chi_drag;
double a;
ccl_cosmology *cosmo;
int *status;
};
static ccl_cosmology *create_w0eff_cosmo(double w0eff, ccl_cosmology *cosmo, int *status) {
// create a cosmology with the same parameters as the input except w0-wa. Instead
// the cosmology is created with w0 = w0eff.
ccl_parameters params_w0eff;
double norm_pk;
double mnu[3];
int i;
for(i=0; i<3; ++i)
mnu[i] = 0;
for(i=0; i<cosmo->params.N_nu_mass; ++i)
mnu[i] = cosmo->params.m_nu[i];
if (isnan(cosmo->params.A_s))
norm_pk = cosmo->params.sigma8;
else
norm_pk = cosmo->params.A_s;
params_w0eff = ccl_parameters_create(
cosmo->params.Omega_c, cosmo->params.Omega_b, cosmo->params.Omega_k,
cosmo->params.Neff, mnu, cosmo->params.N_nu_mass,
w0eff, 0, cosmo->params.h, norm_pk,
cosmo->params.n_s, cosmo->params.bcm_log10Mc, cosmo->params.bcm_etab,
cosmo->params.bcm_ks, cosmo->params.mu_0, cosmo->params.sigma_0,
cosmo->params.c1_mg, cosmo->params.c2_mg, cosmo->params.lambda_mg,
cosmo->params.nz_mgrowth,
cosmo->params.z_mgrowth, cosmo->params.df_mgrowth, status);
if(*status != 0)
return NULL;
return ccl_cosmology_create(params_w0eff, cosmo->config);
}
static double w0eff_func(double w0eff, void *p) {
// function used to compare the distance to the CMB in a test cosmology to
// to the value in the original cosmology
// returns chi_eff - chi
struct hf_model_match_data *hfd = (struct hf_model_match_data*)p;
ccl_cosmology *cosmo_w0eff = NULL;
double chi_drag_w0eff, tmp, zdrag_w0eff;
// make the equivalent cosmology
cosmo_w0eff = create_w0eff_cosmo(w0eff, hfd->cosmo, hfd->status);
if (cosmo_w0eff == NULL) {
*(hfd->status) = CCL_ERROR_MEMORY;
return NAN;
}
// get the comoving distance to zdrag
zdrag_w0eff = zdrag_eh(&(cosmo_w0eff->params));
compute_chi(1.0 / (1.0 + zdrag_w0eff), cosmo_w0eff, &tmp, hfd->status);
chi_drag_w0eff = tmp;
compute_chi(hfd->a, cosmo_w0eff, &tmp, hfd->status);
chi_drag_w0eff -= tmp;
if (*(hfd->status) != 0) {
return NAN;
}
ccl_parameters_free(&(cosmo_w0eff->params));
ccl_cosmology_free(cosmo_w0eff);
return chi_drag_w0eff - hfd->chi_drag;
}
static double get_w0eff(double a, struct hf_model_match_data data) {
// For a given input w0-wa cosmology, this function solves for the value of
// w0eff such that the comoving distance from a to the CMB in a cosmology
// with the same parameters, but with w0, wa = w0eff, 0, is the same as the
// original cosmology.
double w0eff, w0eff_low = -2.0, w0eff_high = -0.35;
double flow, fhigh;
int itr, max_itr = 1000, gsl_status;
const gsl_root_fsolver_type *T;
gsl_root_fsolver *s;
gsl_function F;
data.a = a;
data.chi_drag = ccl_comoving_radial_distance(data.cosmo, 1.0 / (1.0 + zdrag_eh(&(data.cosmo->params))), data.status);
data.chi_drag -= ccl_comoving_radial_distance(data.cosmo, a, data.status);
if(*(data.status) != 0) {
ccl_cosmology_set_status_message(
data.cosmo,
"ccl_halofit.c: get_w0eff(): "
"could not compute chi_drag for cosmology\n");
return NAN;
}
F.function = &w0eff_func;
F.params = &data;
// we have to bound the root, otherwise return -1
// we will fiil in any -1's in the calling routine
flow = w0eff_func(w0eff_low, &data);
fhigh = w0eff_func(w0eff_high, &data);
if (flow * fhigh > 0) {
return -1;
}
T = gsl_root_fsolver_brent;
s = gsl_root_fsolver_alloc(T);
if (s == NULL) {
*(data.status) = CCL_ERROR_MEMORY;
}
else {
gsl_root_fsolver_set(s, &F, w0eff_low, w0eff_high);
itr = 0;
do {
itr++;
gsl_status = gsl_root_fsolver_iterate(s);
if (gsl_status == GSL_EBADFUNC)
break;
w0eff = gsl_root_fsolver_root(s);
w0eff_low = gsl_root_fsolver_x_lower(s);
w0eff_high = gsl_root_fsolver_x_upper(s);
gsl_status = gsl_root_test_interval(
w0eff_low, w0eff_high,
1e-6,
1e-6);
} while (gsl_status == GSL_CONTINUE && itr < max_itr);
gsl_root_fsolver_free(s);
if (gsl_status != GSL_SUCCESS || itr >= max_itr) {
ccl_raise_gsl_warning(
gsl_status, "ccl_halofit.c: get_w0eff(): error in root finding for the halofit matching cosmology\n");
*(data.status) |= gsl_status;
}
}
return w0eff;
}
/* helper data and functions for integrals
the integral is
\int dlnk \Delta^{2}(k) \exp(-k^{2}R^{2})
for halofit, we also need the first and second derivatives of this
integral
*/
struct hf_int_data {
double r;
double r2;
double a;
ccl_cosmology *cosmo;
ccl_f2d_t *plin;
int *status;
gsl_integration_cquad_workspace *workspace;
};
static double gauss_norm_int_func(double lnk, void *p) {
struct hf_int_data *hfd = (struct hf_int_data*)p;
double k = exp(lnk);
double k2 = k*k;
return (
ccl_f2d_t_eval(hfd->plin, lnk, hfd->a, hfd->cosmo, hfd->status) *
k*k2/2.0/M_PI/M_PI *
exp(-k2 * (hfd->r2)));
}
static double onederiv_gauss_norm_int_func(double lnk, void *p) {
struct hf_int_data *hfd = (struct hf_int_data*)p;
double k = exp(lnk);
double k2 = k*k;
return (
ccl_f2d_t_eval(hfd->plin, lnk, hfd->a, hfd->cosmo, hfd->status) *
k*k2/2.0/M_PI/M_PI *
exp(-k2 * (hfd->r2)) *
(-k2 * 2.0 * (hfd->r)));
}
static double twoderiv_gauss_norm_int_func(double lnk, void *p) {
struct hf_int_data *hfd = (struct hf_int_data*)p;
double k = exp(lnk);
double k2 = k*k;
return (
ccl_f2d_t_eval(hfd->plin, lnk, hfd->a, hfd->cosmo, hfd->status) *
k*k2/2.0/M_PI/M_PI *
exp(-k2 * (hfd->r2)) *
(-2.0*k2 + 4.0*k2*k2 * (hfd->r2)));
}
// function whose root is \sigma^2{rsigma, a} = 1
static double rsigma_func(double rsigma, void *p) {
struct hf_int_data *hfd = (struct hf_int_data*)p;
double result, lnkmin, lnkmax;
gsl_function F;
int gsl_status;
lnkmin = hfd->plin->lkmin;
lnkmax = hfd->plin->lkmax;
hfd->r = rsigma;
hfd->r2 = rsigma * rsigma;
F.function = &gauss_norm_int_func;
F.params = (void *)hfd;
gsl_status = gsl_integration_cquad(
&F, lnkmin, lnkmax,
0.0, hfd->cosmo->gsl_params.INTEGRATION_SIGMAR_EPSREL,
hfd->workspace, &result, NULL, NULL);
if (gsl_status != GSL_SUCCESS) {
ccl_raise_gsl_warning(
gsl_status,
"ccl_halofit.c: rsigma_func(): error in integration "
"for finding the halofit non-linear scale\n");
*(hfd->status) |= gsl_status;
}
return result - 1.0;
}
static double get_rsigma(double a, struct hf_int_data data) {
double rsigma, rlow = 1e-2, rhigh = 1e2;
double flow, fhigh;
int itr, max_itr = 1000, gsl_status;
const gsl_root_fsolver_type *T;
gsl_root_fsolver *s;
gsl_function F;
data.a = a;
F.function = &rsigma_func;
F.params = &data;
// we have to bound the root, otherwise return -1
// we will fiil in any -1's in the calling routine
flow = rsigma_func(rlow, &data);
fhigh = rsigma_func(rhigh, &data);
if (flow * fhigh > 0) {
return -1;
}
T = gsl_root_fsolver_brent;
s = gsl_root_fsolver_alloc(T);
if (s == NULL) {
*(data.status) = CCL_ERROR_MEMORY;
}
else {
gsl_root_fsolver_set(s, &F, rlow, rhigh);
itr = 0;
do {
itr++;
gsl_status = gsl_root_fsolver_iterate(s);
if (gsl_status == GSL_EBADFUNC)
break;
rsigma = gsl_root_fsolver_root(s);
rlow = gsl_root_fsolver_x_lower(s);
rhigh = gsl_root_fsolver_x_upper(s);
gsl_status = gsl_root_test_interval(
rlow, rhigh,
data.cosmo->gsl_params.INTEGRATION_SIGMAR_EPSREL,
data.cosmo->gsl_params.INTEGRATION_SIGMAR_EPSREL);
} while (gsl_status == GSL_CONTINUE && itr < max_itr);
gsl_root_fsolver_free(s);
if (gsl_status != GSL_SUCCESS || itr >= max_itr) {
ccl_raise_gsl_warning(
gsl_status, "ccl_halofit.c: get_rsigma(): error in root finding for the halofit non-linear scale\n");
*(data.status) |= gsl_status;
}
}
return rsigma;
}
/*
* Allocate a new struct for storing halofit data
* @param cosmo Cosmological data
* @param int, status of computations
*/
halofit_struct* ccl_halofit_struct_new(ccl_cosmology *cosmo,
ccl_f2d_t *plin, int *status) {
size_t n_a;
int i, gsl_status;
double lnkmin, lnkmax;
double *a_vec = NULL;
double *vals = NULL;
double *vals_om = NULL;
double *vals_de = NULL;
halofit_struct *hf = NULL;
struct hf_int_data data;
gsl_function F;
gsl_integration_cquad_workspace *workspace = NULL;
double result;
double sigma2, rsigma, dsigma2drsigma;
struct hf_model_match_data data_w0eff;
ccl_cosmology *cosmo_w0eff = NULL;
// compute spline point locations and integral bounds
// note that the spline point locations in `a` determine a radius by
// solving sigma2(R, a) = 1
// it is this radius that is needed for the subsequent splines of
// the derivatives.
lnkmin = plin->lkmin;
lnkmax = plin->lkmax;
if(plin->fa != NULL) {
n_a = plin->fa->size;
a_vec = plin->fa->x;
}
else if(plin->fka != NULL) {
n_a = plin->fka->interp_object.ysize;
a_vec = plin->fka->yarr;
}
else {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"input pk2d has no splines.\n");
}
if(*status == 0) {
///////////////////////////////////////////////////////
// memory allocation
hf = (halofit_struct*)malloc(sizeof(halofit_struct));
if (hf == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for halofit_struct\n");
} else {
hf->rsigma = NULL;
hf->sigma2 = NULL;
hf->n_eff = NULL;
hf->C = NULL;
hf->weff = NULL;
hf->omeff = NULL;
hf->deeff = NULL;
}
}
if (*status == 0) {
workspace = gsl_integration_cquad_workspace_alloc(cosmo->gsl_params.N_ITERATION);
if (workspace == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for cquad workspace\n");
}
}
if (*status == 0) {
vals = (double*)malloc(sizeof(double) * n_a);
if (vals == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for results vector\n");
}
}
if (*status == 0) {
vals_om = (double*)malloc(sizeof(double) * n_a);
if (vals_om == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for OmegaM results vector\n");
}
}
if (*status == 0) {
vals_de = (double*)malloc(sizeof(double) * n_a);
if (vals_de == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for OmegaDE results vector\n");
}
}
////////////////////////////////////////////////////////
// if wa != 0, then we need to find an equivalent
// cosmology with wa = 0
data_w0eff.cosmo = cosmo;
data_w0eff.status = status;
if (*status == 0) {
if (cosmo->params.wa != 0) {
for(i=0; i<n_a; ++i) {
vals[i] = get_w0eff(a_vec[i], data_w0eff);
if (*status != 0) {
*status = CCL_ERROR_ROOT;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"could not solve for effective value of w0 for w0-wa cosmology\n");
break;
}
// now get omeff and deff
cosmo_w0eff = create_w0eff_cosmo(vals[i], cosmo, status);
if (cosmo_w0eff == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"could not allocat memory for effective w0 for w0-wa cosmology\n");
break;
}
vals_om[i] = ccl_omega_x(cosmo_w0eff, a_vec[i], ccl_species_m_label, status) +
ccl_omega_x(cosmo_w0eff, a_vec[i], ccl_species_nu_label, status);
vals_de[i] = ccl_omega_x(cosmo_w0eff, a_vec[i], ccl_species_l_label, status);
ccl_parameters_free(&(cosmo_w0eff->params));
ccl_cosmology_free(cosmo_w0eff);
cosmo_w0eff = NULL;
if (*status != 0) {
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"could not compute OmegaM and OmegaDE for cosmology\n");
break;
}
}
} else {
for(i=0; i<n_a; ++i) {
vals[i] = cosmo->params.w0;
vals_om[i] = ccl_omega_x(cosmo, a_vec[i], ccl_species_m_label, status) +
ccl_omega_x(cosmo, a_vec[i], ccl_species_nu_label, status);
vals_de[i] = ccl_omega_x(cosmo, a_vec[i], ccl_species_l_label, status);
if (*status != 0) {
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"could not compute OmegaM and OmegaDE for cosmology\n");
break;
}
}
}
}
// spline the weff values
if (*status == 0) {
hf->weff = gsl_spline_alloc(gsl_interp_akima, n_a);
if (hf->weff == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for weff spline\n");
}
}
if (*status == 0) {
gsl_status = gsl_spline_init(hf->weff, a_vec, vals, n_a);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not build weff spline\n");
}
}
// spline the omeff values
if (*status == 0) {
hf->omeff = gsl_spline_alloc(gsl_interp_akima, n_a);
if (hf->omeff == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for omeff spline\n");
}
}
if (*status == 0) {
gsl_status = gsl_spline_init(hf->omeff, a_vec, vals_om, n_a);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not build omeff spline\n");
}
}
// spline the deeff values
if (*status == 0) {
hf->deeff = gsl_spline_alloc(gsl_interp_akima, n_a);
if (hf->deeff == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for deeff spline\n");
}
}
if (*status == 0) {
gsl_status = gsl_spline_init(hf->deeff, a_vec, vals_de, n_a);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not build deeff spline\n");
}
}
///////////////////////////////////////////////////////
// find the nonlinear scale at each scale factor
if (*status == 0) {
// setup for integrations
data.status = status;
data.cosmo = cosmo;
data.plin = plin;
data.workspace = workspace;
for (i=0; i<n_a; ++i) {
vals[i] = get_rsigma(a_vec[i], data);
if (*status != 0) {
*status = CCL_ERROR_ROOT;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"could not solve for non-linear scale for halofit at scale factor %f\n", a_vec[i]);
break;
}
}
// now go backwards and fill any -1's
// one must work, so set an error if not
if (vals[n_a-1] == -1) {
*status = CCL_ERROR_ROOT;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"could not solve for non-linear scale for halofit at least once\n");
}
if (*status == 0) {
// linearly set rsigma to a very small number at high-z
double min_a = -1, max_a = -1;
double max_val = -1;
double w;
// first non -1 value and scale factor of last -1 value
for (i=1; i<n_a; ++i) {
if (vals[i] != -1) {
max_a = a_vec[i];
max_val = vals[i];
break;
}
}
// scale factor of first -1 value
for (i=0; i<n_a; ++i) {
if (vals[i] == -1) {
min_a = a_vec[i];
break;
}
}
if (min_a != -1) {
// at least one value is -1 so set the zeroth value
vals[0] = 1e-6;
// interp any values that remain -1
for(i=1; i<n_a-1; ++i) {
if (vals[i] == -1) {
w = (a_vec[i] - min_a) / (max_a - min_a);
vals[i] = w * max_val + (1.0 - w) * vals[0];
}
}
}
}
}
// spline the non-linear scales
if (*status == 0) {
hf->rsigma = gsl_spline_alloc(gsl_interp_akima, n_a);
if (hf->rsigma == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for Rsigma spline\n");
}
}
if (*status == 0) {
gsl_status = gsl_spline_init(hf->rsigma, a_vec, vals, n_a);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not build Rsigma spline\n");
}
}
///////////////////////////////////////////////////////
// now compute sigma2(R) at each spline point
// and spline that
// this should be close to 1 OFC, but better to use the exact value
if (*status == 0) {
for (i=0; i<n_a; ++i) {
data.a = a_vec[i];
vals[i] = rsigma_func(gsl_spline_eval(hf->rsigma, a_vec[i], NULL), &data) + 1;
if (*status != 0) {
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not eval "
"points for sigma2(R) spline\n");
break;
}
}
}
if (*status == 0) {
hf->sigma2 = gsl_spline_alloc(gsl_interp_akima, n_a);
if (hf->sigma2 == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for sigma2(R) spline\n");
}
}
if (*status == 0) {
gsl_status = gsl_spline_init(hf->sigma2, a_vec, vals, n_a);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not build sigma2(R) spline\n");
}
}
///////////////////////////////////////////////////////
// now compute the effective spectral index
if (*status == 0) {
F.function = &onederiv_gauss_norm_int_func;
F.params = &data;
for (i=0; i<n_a; ++i) {
rsigma = gsl_spline_eval(hf->rsigma, a_vec[i], NULL);
sigma2 = gsl_spline_eval(hf->sigma2, a_vec[i], NULL);
data.a = a_vec[i];
data.r = rsigma;
data.r2 = rsigma * rsigma;
gsl_status = gsl_integration_cquad(
&F,
lnkmin, lnkmax,
0.0, cosmo->gsl_params.INTEGRATION_SIGMAR_EPSREL,
workspace, &result, NULL, NULL);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_INTEG;
ccl_raise_gsl_warning(
gsl_status,
"ccl_power.c: ccl_halofit_struct_new(): could not eval "
"points for n_eff spline\n");
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not eval "
"points for n_eff spline\n");
break;
}
// this is n_eff but expressed in terms of linear derivs
// see eqn A5 of Takahashi et al.
vals[i] = -rsigma / sigma2 * result - 3.0;
}
}
if (*status == 0) {
hf->n_eff = gsl_spline_alloc(gsl_interp_akima, n_a);
if (hf->n_eff == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for n_eff spline\n");
}
}
if (*status == 0) {
gsl_status = gsl_spline_init(hf->n_eff, a_vec, vals, n_a);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not build n_eff spline\n");
}
}
///////////////////////////////////////////////////////
// now compute the curvature C
if (*status == 0) {
F.function = &twoderiv_gauss_norm_int_func;
F.params = &data;
for (i=0; i<n_a; ++i) {
rsigma = gsl_spline_eval(hf->rsigma, a_vec[i], NULL);
sigma2 = gsl_spline_eval(hf->sigma2, a_vec[i], NULL);
// we need to solve for the deriv we need from n_eff here
dsigma2drsigma = gsl_spline_eval(hf->n_eff, a_vec[i], NULL);
dsigma2drsigma = (dsigma2drsigma + 3.0) / (-rsigma / sigma2);
data.a = a_vec[i];
data.r = rsigma;
data.r2 = rsigma * rsigma;
gsl_status = gsl_integration_cquad(
&F,
lnkmin, lnkmax,
0.0, cosmo->gsl_params.INTEGRATION_SIGMAR_EPSREL,
workspace, &result, NULL, NULL);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_INTEG;
ccl_raise_gsl_warning(
gsl_status,
"ccl_power.c: ccl_halofit_struct_new(): could not eval "
"points for C spline\n");
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not eval "
"points for C spline\n");
break;
}
// this is C but expressed in terms of linear derivs
// see eqn A5 of Takahashi et al.
vals[i] = (
-1.0 * (
result * rsigma * rsigma / sigma2 +
dsigma2drsigma * rsigma / sigma2 -
dsigma2drsigma * dsigma2drsigma * rsigma * rsigma / sigma2 / sigma2));
}
}
if (*status == 0) {
hf->C = gsl_spline_alloc(gsl_interp_akima, n_a);
if (hf->C == NULL) {
*status = CCL_ERROR_MEMORY;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): "
"memory could not be allocated for C spline\n");
}
}
if (*status == 0) {
gsl_status = gsl_spline_init(hf->C, a_vec, vals, n_a);
if (gsl_status != GSL_SUCCESS) {
*status = CCL_ERROR_SPLINE;
ccl_cosmology_set_status_message(
cosmo,
"ccl_halofit.c: ccl_halofit_struct_new(): could not build C spline\n");
}
}
// free stuff on the way out
// if the status is non-zero, then we should free any data already
// accumulated
if (*status != 0) {
ccl_halofit_struct_free(hf);
hf = NULL;
}
gsl_integration_cquad_workspace_free(workspace);
free(vals);
free(vals_om);
free(vals_de);
if (cosmo_w0eff != NULL) {
ccl_parameters_free(&(cosmo_w0eff->params));
ccl_cosmology_free(cosmo_w0eff);
}
return hf;
}
/*
* Free a halofit struct
* @param hf, pointer to halofit struct to free
*/
void ccl_halofit_struct_free(halofit_struct *hf) {
if (hf != NULL) {
if (hf->rsigma != NULL)
gsl_spline_free(hf->rsigma);
if (hf->sigma2 != NULL)
gsl_spline_free(hf->sigma2);
if (hf->n_eff != NULL)
gsl_spline_free(hf->n_eff);
if (hf->C != NULL)
gsl_spline_free(hf->C);
if (hf->weff != NULL)
gsl_spline_free(hf->weff);
if (hf->omeff != NULL)
gsl_spline_free(hf->omeff);
if (hf->deeff != NULL)
gsl_spline_free(hf->deeff);
free(hf);
}
}
/**
* Computes the halofit non-linear power spectrum
* @param cosmo: cosmology object containing parameters
* @param lk: natural logarithm of wavenumber in units of Mpc^{-1}
* @param a: scale factor normalised to a=1 today
* @param status: Status flag: 0 if there are no errors, non-zero otherwise
* @param hf: halofit splines for evaluating the power spectrum
* @return halofit_matter_power: halofit power spectrum, P(k), units of Mpc^{3}
*/
double ccl_halofit_power(ccl_cosmology *cosmo, ccl_f2d_t *plin,
double lk, double a, halofit_struct *hf, int *status) {
double rsigma, neff, C;
double ksigma, weffa, omegaMz, omegaDEwz, kh;
double PkL, PkNL, f1, f2, f3, an, bn, cn, gamman, alphan, betan, nun, mun, y, fy;
double DeltakL, DeltakL_tilde, DeltakQ, DeltakH, DeltakHprime, DeltakNL;
double Qnu, fnu;
double f1a, f2a, f3a, f1b, f2b, f3b, fb_frac;
double neff2, neff3, neff4;
double kh2, y2;
double delta2_norm, om_nu;
double k=exp(lk);
// all eqns are from Takahashi et al. unless stated otherwise
// eqns A4 - A5
rsigma = gsl_spline_eval(hf->rsigma, a, NULL);
neff = gsl_spline_eval(hf->n_eff, a, NULL);
C = gsl_spline_eval(hf->C, a, NULL);
weffa = cosmo->params.w0;
omegaMz = ccl_omega_x(cosmo, a, ccl_species_m_label, status);
omegaDEwz = ccl_omega_x(cosmo, a, ccl_species_l_label, status);
// not using these to match CLASS better - might be a bug in CLASS
// weffa = gsl_spline_eval(hf->weff, a, NULL);
// omegaMz = gsl_spline_eval(hf->omeff, a, NULL);
// omegaDEwz = gsl_spline_eval(hf->deeff, a, NULL);
ksigma = 1.0 / rsigma;
neff2 = neff * neff;
neff3 = neff2 * neff;
neff4 = neff3 * neff;
delta2_norm = k*k*k/2.0/M_PI/M_PI;
// compute the present day neutrino massive neutrino fraction
// uses all neutrinos even if they are moving fast
om_nu = cosmo->params.sum_nu_masses / 93.14 / cosmo->params.h / cosmo->params.h;
fnu = om_nu / (cosmo->params.Omega_m);
// eqns A6 - A13 of Takahashi et al.
an = pow(
10.0,
1.5222 + 2.8553*neff + 2.3706*neff2 + 0.9903*neff3 +
0.2250*neff4 - 0.6038*C + 0.1749*omegaDEwz*(1.0 + weffa));
bn = pow(10.0, -0.5642 + 0.5864*neff + 0.5716*neff2 - 1.5474*C + 0.2279*omegaDEwz*(1.0 + weffa));
cn = pow(10.0, 0.3698 + 2.0404*neff + 0.8161*neff2 + 0.5869*C);
gamman = 0.1971 - 0.0843*neff + 0.8460*C;
alphan = fabs(6.0835 + 1.3373*neff - 0.1959*neff2 - 5.5274*C);
betan = 2.0379 - 0.7354*neff + 0.3157*neff2 + 1.2490*neff3 + 0.3980*neff4 - 0.1682*C;
mun = 0.0;
nun = pow(10.0, 5.2105 + 3.6902*neff);
// eqns C17 and C18 for Smith et al.
if (fabs(1.0 - omegaMz) > 0.01) {
f1a = pow(omegaMz, -0.0732);
f2a = pow(omegaMz, -0.1423);
f3a = pow(omegaMz, 0.0725);
f1b = pow(omegaMz, -0.0307);
f2b = pow(omegaMz, -0.0585);
f3b = pow(omegaMz, 0.0743);
fb_frac = omegaDEwz / (1.0 - omegaMz);
f1 = fb_frac * f1b + (1.0 - fb_frac) * f1a;
f2 = fb_frac * f2b + (1.0 - fb_frac) * f2a;
f3 = fb_frac * f3b + (1.0 - fb_frac) * f3a;
} else {
f1 = 1.0;
f2 = 1.0;
f3 = 1.0;
}
// correction to betan from Bird et al., eqn A10
betan += (fnu * (1.081 + 0.395*neff2));
// eqns A1 - A3
PkL = ccl_f2d_t_eval(plin, lk, a, cosmo, status);
y = k/ksigma;
y2 = y * y;
fy = y/4.0 + y2/8.0;
DeltakL = PkL * delta2_norm;
// correction to DeltakL from Bird et al., eqn A9
kh = k / cosmo->params.h;
kh2 = kh * kh;
DeltakL_tilde = DeltakL * (1.0 + fnu * (47.48 * kh2) / (1.0 + 1.5 * kh2));
DeltakQ = DeltakL * pow(1.0 + DeltakL_tilde, betan) / (1.0 + alphan*DeltakL_tilde) * exp(-fy);
DeltakHprime = an * pow(y, 3.0*f1) / (1.0 + bn*pow(y, f2) + pow(cn*f3*y, 3.0 - gamman));
DeltakH = DeltakHprime / (1.0 + mun/y + nun/y2);
// correction to DeltakH from Bird et al., eqn A6-A7
Qnu = fnu * (0.977 - 18.015 * (cosmo->params.Omega_m - 0.3));
DeltakH *= (1.0 + Qnu);
DeltakNL = DeltakQ + DeltakH;
PkNL = DeltakNL / delta2_norm;
// we check the status once
if(*status != 0)
return NAN;
else
return PkNL;
}
| {
"alphanum_fraction": 0.6138519924,
"avg_line_length": 30.2997946612,
"ext": "c",
"hexsha": "04e0103c8fa81ea05ba6333f49181b5002572318",
"lang": "C",
"max_forks_count": 54,
"max_forks_repo_forks_event_max_datetime": "2022-02-06T13:12:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-12T13:08:25.000Z",
"max_forks_repo_head_hexsha": "a37cad61f060f3928fa5d47b1e2670db3e9bce6f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Jappenn/CCL",
"max_forks_repo_path": "src/ccl_halofit.c",
"max_issues_count": 703,
"max_issues_repo_head_hexsha": "a37cad61f060f3928fa5d47b1e2670db3e9bce6f",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T14:40:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-07-07T16:27:17.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "Jappenn/CCL",
"max_issues_repo_path": "src/ccl_halofit.c",
"max_line_length": 119,
"max_stars_count": 91,
"max_stars_repo_head_hexsha": "a37cad61f060f3928fa5d47b1e2670db3e9bce6f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "Jappenn/CCL",
"max_stars_repo_path": "src/ccl_halofit.c",
"max_stars_repo_stars_event_max_datetime": "2022-03-28T08:55:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-07-14T02:45:59.000Z",
"num_tokens": 9636,
"size": 29512
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.