output_csv.f90 Source File


This file depends on

sourcefile~~output_csv.f90~~EfferentGraph sourcefile~output_csv.f90 output_csv.f90 sourcefile~globals.f90 globals.f90 sourcefile~output_csv.f90->sourcefile~globals.f90

Files dependent on this one

sourcefile~~output_csv.f90~~AfferentGraph sourcefile~output_csv.f90 output_csv.f90 sourcefile~analyze.f90 analyze.f90 sourcefile~analyze.f90->sourcefile~output_csv.f90 sourcefile~write_modes.f90 write_modes.f90 sourcefile~analyze.f90->sourcefile~write_modes.f90 sourcefile~mhd3d_vars.f90 mhd3d_vars.f90 sourcefile~analyze.f90->sourcefile~mhd3d_vars.f90 sourcefile~hmap_axisnb.f90 hmap_axisNB.f90 sourcefile~hmap_axisnb.f90->sourcefile~output_csv.f90 sourcefile~hmap_frenet.f90 hmap_frenet.f90 sourcefile~hmap_frenet.f90->sourcefile~output_csv.f90 sourcefile~write_modes.f90->sourcefile~output_csv.f90 sourcefile~gvec_post.f90 gvec_post.f90 sourcefile~gvec_post.f90->sourcefile~analyze.f90 sourcefile~functional.f90 functional.f90 sourcefile~gvec_post.f90->sourcefile~functional.f90 sourcefile~gvec_post.f90->sourcefile~mhd3d_vars.f90 sourcefile~readstate_vars.f90 readstate_vars.f90 sourcefile~gvec_post.f90->sourcefile~readstate_vars.f90 sourcefile~mhd3d_evalfunc.f90 mhd3d_evalfunc.f90 sourcefile~gvec_post.f90->sourcefile~mhd3d_evalfunc.f90 sourcefile~restart.f90 restart.f90 sourcefile~gvec_post.f90->sourcefile~restart.f90 sourcefile~hmap.f90 hmap.f90 sourcefile~hmap.f90->sourcefile~hmap_axisnb.f90 sourcefile~hmap.f90->sourcefile~hmap_frenet.f90 sourcefile~mhd3d.f90 mhd3d.f90 sourcefile~mhd3d.f90->sourcefile~analyze.f90 sourcefile~mhd3d.f90->sourcefile~hmap.f90 sourcefile~lambda_solve.f90 lambda_solve.f90 sourcefile~mhd3d.f90->sourcefile~lambda_solve.f90 sourcefile~mhd3d.f90->sourcefile~mhd3d_vars.f90 sourcefile~mhd3d.f90->sourcefile~mhd3d_evalfunc.f90 sourcefile~mhd3d.f90->sourcefile~restart.f90 sourcefile~rungvec.f90 rungvec.f90 sourcefile~rungvec.f90->sourcefile~analyze.f90 sourcefile~rungvec.f90->sourcefile~functional.f90 sourcefile~rungvec.f90->sourcefile~mhd3d_vars.f90 sourcefile~rungvec.f90->sourcefile~restart.f90 sourcefile~state.f90 state.f90 sourcefile~state.f90->sourcefile~analyze.f90 sourcefile~state.f90->sourcefile~hmap.f90 sourcefile~state.f90->sourcefile~functional.f90 sourcefile~state.f90->sourcefile~mhd3d_vars.f90 sourcefile~state.f90->sourcefile~readstate_vars.f90 sourcefile~sfl_boozer.f90 sfl_boozer.f90 sourcefile~state.f90->sourcefile~sfl_boozer.f90 sourcefile~state.f90->sourcefile~restart.f90 sourcefile~functional.f90->sourcefile~mhd3d.f90 sourcefile~gvec.f90 gvec.f90 sourcefile~gvec.f90->sourcefile~rungvec.f90 sourcefile~lambda_solve.f90->sourcefile~hmap.f90 sourcefile~mhd3d_vars.f90->sourcefile~hmap.f90 sourcefile~readstate.f90 readstate.f90 sourcefile~readstate.f90->sourcefile~hmap.f90 sourcefile~readstate.f90->sourcefile~readstate_vars.f90 sourcefile~readstate_vars.f90->sourcefile~hmap.f90 sourcefile~run.f90 run.f90 sourcefile~run.f90->sourcefile~rungvec.f90 sourcefile~sfl_boozer.f90->sourcefile~hmap.f90 sourcefile~sfl_boozer.f90->sourcefile~lambda_solve.f90 sourcefile~transform_sfl.f90 transform_sfl.f90 sourcefile~transform_sfl.f90->sourcefile~hmap.f90 sourcefile~transform_sfl.f90->sourcefile~sfl_boozer.f90 sourcefile~gvec_to_castor3d_vars.f90 gvec_to_castor3d_vars.f90 sourcefile~gvec_to_castor3d_vars.f90->sourcefile~transform_sfl.f90 sourcefile~gvec_to_gene_vars.f90 gvec_to_gene_vars.f90 sourcefile~gvec_to_gene_vars.f90->sourcefile~transform_sfl.f90 sourcefile~gvec_to_hopr_vars.f90 gvec_to_hopr_vars.f90 sourcefile~gvec_to_hopr_vars.f90->sourcefile~transform_sfl.f90 sourcefile~gvec_to_jorek.f90 gvec_to_jorek.f90 sourcefile~gvec_to_jorek.f90->sourcefile~readstate.f90 sourcefile~gvec_to_jorek.f90->sourcefile~readstate_vars.f90 sourcefile~mhd3d_evalfunc.f90->sourcefile~mhd3d_vars.f90 sourcefile~restart.f90->sourcefile~mhd3d_vars.f90 sourcefile~restart.f90->sourcefile~readstate.f90 sourcefile~restart.f90->sourcefile~readstate_vars.f90 sourcefile~restart.f90->sourcefile~mhd3d_evalfunc.f90 sourcefile~convert_gvec_to_jorek.f90 convert_gvec_to_jorek.f90 sourcefile~convert_gvec_to_jorek.f90->sourcefile~gvec_to_jorek.f90

Source Code

!===================================================================================================================================
! Copyright (c) 2025 GVEC Contributors, Max Planck Institute for Plasma Physics
! License: MIT
!===================================================================================================================================
#include "defines.h"

!===================================================================================================================================
!>
!!# Module **Output CSV**
!!
!!
!!
!===================================================================================================================================
MODULE MODgvec_Output_CSV
! MODULES
USE MODgvec_Globals, ONLY: wp
IMPLICIT NONE
PRIVATE

INTERFACE WriteDataToCSV
  MODULE PROCEDURE WriteDataToCSV
END INTERFACE

PUBLIC::WriteDataToCSV
!===================================================================================================================================

CONTAINS

!===================================================================================================================================
!> Subroutine to write
!!
!===================================================================================================================================
SUBROUTINE WriteDataToCSV(VarNames,Values,FileString,append_in,vfmt_in)
! MODULES
USE MODgvec_Globals,ONLY:Unit_stdOut,GETFREEUNIT
! IMPLICIT VARIABLE HANDLING
IMPLICIT NONE
!-----------------------------------------------------------------------------------------------------------------------------------
! INPUT VARIABLES
CHARACTER(LEN=*),INTENT(IN)   :: VarNames(:)          !! Variable names,
REAL(wp),INTENT(IN)           :: Values(:,:)      !! variable data
CHARACTER(LEN=*),INTENT(IN)   :: FileString              !! Output file name
LOGICAL,INTENT(IN),OPTIONAL   :: append_in                  !! append data
CHARACTER(LEN=*),INTENT(IN),OPTIONAL   :: vfmt_in           !! value format
!-----------------------------------------------------------------------------------------------------------------------------------
! OUTPUT VARIABLES
!-----------------------------------------------------------------------------------------------------------------------------------
! LOCAL VARIABLES
INTEGER                       :: nVal                    !! Number of output Values
INTEGER                       :: nPlot                   !! number of 1D values
INTEGER                        :: iVal,iPlot,ioUnit
LOGICAL                        :: append
CHARACTER(LEN=10)              :: vfmt
!===================================================================================================================================
nVal=SIZE(VarNames,1)
IF(SIZE(Values,1).NE.nVal) STOP 'number of values /= nVariables in csv output'
nPlot=SIZE(Values,2)
ioUnit=GETFREEUNIT()
IF(PRESENT(append_in))THEN
  append=append_in
ELSE
  append=.FALSE.
END IF
IF(PRESENT(vfmt_in))THEN
  vfmt=vfmt_in
ELSE
  vfmt='e23.15'
END IF
IF(append)THEN
  WRITE(UNIT_stdOut,'(A)',ADVANCE='NO')'     APPEND DATA TO CSV FILE "'//TRIM(FileString)//'" ...'
  OPEN(UNIT     = ioUnit       ,&
       FILE     = TRIM(FileString)   ,&
       STATUS   = 'OLD'   ,&
       POSITION = 'APPEND'   ,&
       ACCESS   = 'SEQUENTIAL' )
ELSE
  WRITE(UNIT_stdOut,'(A)',ADVANCE='NO')'   WRITE DATA TO CSV FILE    "'//TRIM(FileString)//'" ...'
  OPEN(UNIT     = ioUnit       ,&
       FILE     = TRIM(FileString)   ,&
       STATUS   = 'REPLACE'   ,&
       ACCESS   = 'SEQUENTIAL' )
END IF


DO iVal=1,nVal-1
  WRITE(ioUnit,'(A,1X,(","))',ADVANCE='NO' )  '"'//TRIM(varNames(iVal))//'"'
END DO
WRITE(ioUnit,'(A)')  '"'//TRIM(varNames(nVal))//'"'

DO iPlot=1,nPlot
  WRITE(ioUnit,'(*('//TRIM(vfmt)//',:,","))') Values(:,iPlot)+SIGN(1.0e-99,Values(:,iPlot))
END DO

CLOSE(ioUnit)

WRITE(UNIT_stdOut,'(A)',ADVANCE='YES')"   DONE"
END SUBROUTINE WriteDataToCSV



END MODULE MODgvec_Output_CSV