Loading...
Searching...
No Matches
write2d.c
Go to the documentation of this file.
/*!
* \file secpar2d.c
*
* \author H. Mitasova, I. Kosinovsky, D. Gerdes Fall 1993 (original authors)
* \author modified by McCauley in August 1995
* \author modified by Mitasova in August 1995
* \author H. Mitasova (University of Illinois)
* \author I. Kosinovsky, (USA-CERL)
* \author D.Gerdes (USA-CERL)
*
* \copyright
* (C) 1993-1995 by Helena Mitasova and the GRASS Development Team
*
* \copyright
* This program is free software under the
* GNU General Public License (>=v2).
* Read the file COPYING that comes with GRASS for details.
*/
#include <grass/config.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include <grass/interpf.h>
/* parameter descriptions takes from a strange comment */
/*!
* Writes az,adx,...,adxy into appropriate place (depending on ngstc, nszc
* and offset) in corresponding temp file
*/
int IL_write_temp_2d(struct interp_params *params,
int ngstc, /*!< begin. column */
int nszc, /*!< end. column */
off_t offset2 /*!< offset */
)
{
int j;
static FCELL *array_cell = NULL;
if (!array_cell)
array_cell = G_malloc(sizeof(FCELL) * params->nsizc + 1);
if (params->Tmp_fd_z != NULL) {
for (j = ngstc; j <= nszc; j++)
array_cell[j - 1] = (FCELL)params->az[j];
G_fseek(params->Tmp_fd_z, offset2, SEEK_SET);
if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
params->Tmp_fd_z))
G_fatal_error(_("Cannot write files"));
}
if (params->Tmp_fd_dx != NULL) {
for (j = ngstc; j <= nszc; j++)
if (!params->deriv)
array_cell[j - 1] = (FCELL)params->adx[j];
else
array_cell[j - 1] = (FCELL)(params->adx[j] * params->scik1);
G_fseek(params->Tmp_fd_dx, offset2, SEEK_SET);
if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
params->Tmp_fd_dx))
G_fatal_error(_("Cannot write files"));
}
if (params->Tmp_fd_dy != NULL) {
for (j = ngstc; j <= nszc; j++) {
if (!params->deriv) {
if (params->ady[j] > 0. && params->ady[j] < 0.5)
params->ady[j] = 360.;
array_cell[j - 1] = (FCELL)params->ady[j];
}
else
array_cell[j - 1] = (FCELL)(params->ady[j] * params->scik1);
}
G_fseek(params->Tmp_fd_dy, offset2, SEEK_SET);
if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
params->Tmp_fd_dy))
G_fatal_error(_("Cannot write files"));
}
if (params->Tmp_fd_xx != NULL) {
for (j = ngstc; j <= nszc; j++) {
array_cell[j - 1] = (FCELL)(params->adxx[j] * params->scik1);
}
G_fseek(params->Tmp_fd_xx, offset2, SEEK_SET);
if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
params->Tmp_fd_xx))
G_fatal_error(_("Cannot write files"));
}
if (params->Tmp_fd_yy != NULL) {
for (j = ngstc; j <= nszc; j++)
array_cell[j - 1] = (FCELL)(params->adyy[j] * params->scik2);
G_fseek(params->Tmp_fd_yy, offset2, SEEK_SET);
if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
params->Tmp_fd_yy))
G_fatal_error(_("Cannot write files"));
}
if (params->Tmp_fd_xy != NULL) {
for (j = ngstc; j <= nszc; j++)
array_cell[j - 1] = (FCELL)(params->adxy[j] * params->scik3);
G_fseek(params->Tmp_fd_xy, offset2, SEEK_SET);
if (!fwrite(array_cell + ngstc - 1, sizeof(FCELL), nszc - ngstc + 1,
params->Tmp_fd_xy))
G_fatal_error(_("Cannot write files"));
}
return 1;
}
NULL
#define NULL
Definition ccmath.h:32
G_fatal_error
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition gis/error.c:159
interp_params
Definition interpf.h:70
interp_params::Tmp_fd_xx
FILE * Tmp_fd_xx
Definition interpf.h:123
interp_params::Tmp_fd_xy
FILE * Tmp_fd_xy
Definition interpf.h:123
interp_params::scik2
int scik2
Definition interpf.h:102
interp_params::az
DCELL * az
Definition interpf.h:94
interp_params::deriv
int deriv
Definition interpf.h:114
interp_params::Tmp_fd_yy
FILE * Tmp_fd_yy
Definition interpf.h:123
interp_params::adxy
DCELL * adxy
Definition interpf.h:94
interp_params::scik3
int scik3
Definition interpf.h:102
interp_params::Tmp_fd_dx
FILE * Tmp_fd_dx
Definition interpf.h:123
interp_params::adyy
DCELL * adyy
Definition interpf.h:94
interp_params::adx
DCELL * adx
Definition interpf.h:94
interp_params::Tmp_fd_z
FILE * Tmp_fd_z
Definition interpf.h:123
interp_params::ady
DCELL * ady
Definition interpf.h:94
interp_params::nsizc
int nsizc
Definition interpf.h:92
interp_params::Tmp_fd_dy
FILE * Tmp_fd_dy
Definition interpf.h:123
interp_params::adxx
DCELL * adxx
Definition interpf.h:94
interp_params::scik1
int scik1
Definition interpf.h:102
IL_write_temp_2d
int IL_write_temp_2d(struct interp_params *params, int ngstc, int nszc, off_t offset2)
Definition write2d.c:34