Skip to content

Commit

Permalink
Added the particles2atm and atm2particles functions...
Browse files Browse the repository at this point in the history
  • Loading branch information
janhclem committed Feb 20, 2025
1 parent f9027dd commit 91d5855
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/mptrac.c
Original file line number Diff line number Diff line change
Expand Up @@ -11986,3 +11986,38 @@ void write_vtk(
/* Close file... */
fclose(out);
}

/*****************************************************************************/

void atm2particles(atm_t* atm, particle_t particles[], ctl_t ctl) {

for (int ip = 0; ip < atm->np; ip++) {

particles[ip].time = atm->time[ip];
particles[ip].lon = atm->lon[ip];
particles[ip].lat = atm->lat[ip];
particles[ip].p = atm->p[ip];

for (int iq = 0; iq < ctl.nq; iq++)
particles[ip].q[iq] = atm->q[iq][ip];

}

}

/*****************************************************************************/

void particles2atm(atm_t* atm, particle_t particles[], ctl_t ctl) {

for (int ip = 0; ip < atm->np; ip++) {
atm->time[ip] = particles[ip].time;
atm->lon[ip] = particles[ip].lon;
atm->lat[ip] = particles[ip].lat;
atm->p[ip] = particles[ip].p;

for (int iq = 0; iq < ctl.nq; iq++)
atm->q[iq][ip] = particles[ip].q[iq];

}

}
48 changes: 48 additions & 0 deletions src/mptrac.h
Original file line number Diff line number Diff line change
Expand Up @@ -8666,5 +8666,53 @@ void write_vtk(
const ctl_t * ctl,
const atm_t * atm,
const double t);

/**
* @brief Converts atmospheric data to particle data.
*
* The `atm2particles` function converts data from an atmospheric data
* structure (`atm_t`) to an array of particle structures (`particle_t`).
* It iterates over each particle and assigns corresponding values from
* the atmospheric data based on control parameters (`ctl_t`).
*
* @param atm A pointer to an `atm_t` structure containing atmospheric data.
* @param particles An array of `particle_t` structures to be populated with data.
* @param ctl A `ctl_t` structure containing control parameters.
*
* The function performs the following steps:
* - Iterates through each particle index up to the number of particles (`np`) in `atm`.
* - Assigns time, longitude, latitude, and pressure values from `atm` to each particle.
* - Copies additional quantities (`q`) from `atm` to each particle based on the number of quantities (`nq`) in `ctl`.
*
* @note This function assumes that the `particles` array is pre-allocated with sufficient
* memory to hold `np` particles. The `ctl` structure must be properly initialized.
*
* @author Jan CLEMENS
*/
void atm2particles(atm_t* atm, particle_t particles[], ctl_t ctl);

/**
* @brief Converts particle data to atmospheric data.
*
* The `particles2atm` function converts data from an array of particle
* structures (`particle_t`) to an atmospheric data structure (`atm_t`).
* It iterates over each particle and assigns corresponding values to
* the atmospheric data based on control parameters (`ctl_t`).
*
* @param atm A pointer to an `atm_t` structure to be populated with data.
* @param particles An array of `particle_t` structures containing particle data.
* @param ctl A `ctl_t` structure containing control parameters.
*
* The function performs the following steps:
* - Iterates through each particle index up to the number of particles (`np`) in `atm`.
* - Assigns time, longitude, latitude, and pressure values from each particle to `atm`.
* - Copies additional quantities (`q`) from each particle to `atm` based on the number of quantities (`nq`) in `ctl`.
*
* @note This function assumes that the `atm` structure is pre-allocated with sufficient
* memory to hold data for `np` particles. The `ctl` structure must be properly initialized.
*
* @author Your Name
*/
void particles2atm(atm_t* atm, particle_t particles[], ctl_t ctl);

#endif /* LIBTRAC_H */

0 comments on commit 91d5855

Please sign in to comment.