#include "IonIO.h" #include "ION.h" /***********************************************************************/ /// Open an Ionosphere HDF file for writting /** * Creates an HDF file named * "[prefix]_ion_[stepIdentification].[suffix]" for writting * ionosphere data. * * If mjd > 0, assume UTIO... and write the MJD to the HDF file. * * @example Using UTIO naming, "MyRun_ion_2008-01-01T01-01-00.hdf" * @example Using standard I/O naming: "MyRun_ion_1234567.hdf" * * @param prefix - "base name" of the run * @param stepIdentification - UTIO string (YYYY-MM-DDTHH-MM-SS) or time step number (0000001) * @param suffix - file extension (usually hdf or dmp) * @param mjd - Modified Julian Date (should be > 0). * @param iStep - integer timestep into simulation * @param Time - elapsed simulation time * * @seealso DateTime class for more information on Modified Julian Dates * * @fixme Parse HDF 'istatus' variable so this function doesn't ALWAYS return true */ bool IonIO::open_write_hdf(char *prefix, char *stepIdentification, char *suffix, double *mjd, int *iStep, double *Time) { #ifdef DEBUG_MODE_ON printf("DEBUG: in IonIO.C::open_write_hdf(...)\n"); #endif int istatus = ION_OPEN_WRITE_HDF(prefix, stepIdentification, suffix, mjd, iStep, Time); return true; } /***********************************************************************/ /// Write Ionospheric data to file /** * @param ion - Ionosphere parameters to write to file * @param iStep - timestep to write * @param Time - elapsed simulation time. * * @fixme Parse HDF 'istatus' variable so this function doesn't ALWAYS return true */ bool IonIO::write_data(ION *ion, int *iStep, double *Time) { #ifdef DEBUG_MODE_ON printf("DEBUG: in IonIO.C::write_data(...)\n"); #endif int istatus, njp1, nkp1, nion_i, nion_j; Range Master_range(0,0); // noGuard strips guard cells to make indexing easy for dump Partitioning_Type noGuard(Master_range); noGuard.partitionAlongAxis(0,FALSE,0); noGuard.partitionAlongAxis(1,FALSE,0); noGuard.partitionAlongAxis(2,FALSE,0); // Get the ionospheric Grid information out //noGuard.display("before 2D stuff"); fflush(NULL); njp1 = N_J+1; nkp1 = N_K+1; nion_i = NION_I; nion_j = NION_J; FloatARRAY II_VAR(njp1,nkp1,noGuard); II_VAR.setBase(1); FloatARRAY I_VAR(nion_i, nion_j, noGuard); I_VAR.setBase(1); Range Jp1(1,njp1); Range Kp1(1,nkp1); Range ION_I(1,nion_i); Range ION_J(1,nion_j); // fix the y2ion and yinterp arrays if (ion->ION_PROCESSOR) { FLOP_Y(); } I_VAR(ION_I,ION_J) = ion->X2ion(ION_I,ION_J); istatus=ION2D_DUMP_VAR("x2ion\0",I_VAR.getDataPointer(),&nion_i,&nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Y2ion(ION_I,ION_J); istatus=ION2D_DUMP_VAR("y2ion\0",I_VAR.getDataPointer(),&nion_i,&nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->X_interp(ION_I,ION_J); istatus=ION2D_DUMP_VAR("x_interp\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Y_interp(ION_I,ION_J); istatus=ION2D_DUMP_VAR("y_interp\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); // now put y2ion back where it belongs if (ion->ION_PROCESSOR) { UNFLOP_Y(); } /* Now dump the variables */ II_VAR(Jp1,Kp1) = ion->J0(Jp1,Kp1); istatus=ION2D_DUMP_VAR("J0\0",II_VAR.getDataPointer(),&njp1,&nkp1,iStep,Time); II_VAR(Jp1,Kp1) = ion->Rho0(Jp1,Kp1); istatus=ION2D_DUMP_VAR("rho0\0",II_VAR.getDataPointer(),&njp1,&nkp1,iStep,Time); II_VAR(Jp1,Kp1) = ion->C0(Jp1,Kp1); istatus=ION2D_DUMP_VAR("c0\0",II_VAR.getDataPointer(),&njp1,&nkp1,iStep,Time); I_VAR(ION_I,ION_J) = ion->J1_interp_N; istatus=ION2D_DUMP_VAR("curnorth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Phi_N; istatus=ION2D_DUMP_VAR("potnorth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Sigma_H_N; istatus=ION2D_DUMP_VAR("SigmaH_north\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Sigma_P_N; istatus=ION2D_DUMP_VAR("SigmaP_north\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Flux_N; istatus=ION2D_DUMP_VAR("fluxnorth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Av_Energy_N; istatus=ION2D_DUMP_VAR("avE_north",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->J1_interp_S; istatus=ION2D_DUMP_VAR("cursouth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Phi_S; istatus=ION2D_DUMP_VAR("potsouth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Sigma_H_S; istatus=ION2D_DUMP_VAR("SigmaH_south\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Sigma_P_S; istatus=ION2D_DUMP_VAR("SigmaP_south\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Flux_S; istatus=ION2D_DUMP_VAR("fluxsouth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); I_VAR(ION_I,ION_J) = ion->Av_Energy_S; istatus=ION2D_DUMP_VAR("avE_south",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); return true; } /***********************************************************************/ /// Open an Ionosphere HDF file for reading /** * Reads data from a file named "[prefix]_ion_[stepIdentification].[suffix]". * * @example Using UTIO naming, "MyRun_ion_2008-01-01T01-01-00.hdf" * @example Using standard I/O naming: "MyRun_ion_1234567.hdf" * If mjd > 0, assume UTIO... and write the MJD to the HDF file. * * @param prefix - "base name" of the run * @param stepIdentification - UTIO string (YYYY-MM-DDTHH-MM-SS) or time step number (0000001) * @param suffix - file extension (usually hdf or dmp) * @param mjd - Modified Julian Date (should be > 0). * @param iStep - integer timestep into simulation * @param Time - elapsed simulation time * * @seealso DateTime class for more information on Modified Julian Dates * * @fixme Parse HDF 'istatus' variable so this function doesn't ALWAYS return true */ bool IonIO::open_read_hdf(char *prefix, char *stepIdentification, char *suffix, double *mjd, int *iStep, double *Time) { #ifdef DEBUG_MODE_ON printf("DEBUG: in IonIO.C::open_read_hdf(...)\n"); #endif int istatus = ION_OPEN_READ_HDF(prefix, stepIdentification, suffix, mjd, iStep,Time); return true; } /***********************************************************************/ /// Read ION variables from file /** * Read data using the FORTRAN IO interface (iontake-para.F) * * @param ion - Ionosphere parameters to read * @param iStep - timestep to read ata * @param Time - anticipated simulation time. * * @fixme - Make sure that currentStep and simTime are read in properly! * @fixme Parse HDF 'istatus' variable so this function doesn't ALWAYS return true */ bool IonIO::read_data(ION *ion, int *iStep, double *Time) { #ifdef DEBUG_MODE_ON printf("DEBUG: in IonIO.C::read_data(...)\n"); #endif int istatus, njp1, nkp1, nion_i, nion_j; // Guard partition matches MHD_P -- needed for data transfer Range Master_range(0,0); // noGuard strips guard cells to make indexing easy for dump Partitioning_Type noGuard(Master_range); noGuard.partitionAlongAxis(0,FALSE,0); noGuard.partitionAlongAxis(1,FALSE,0); noGuard.partitionAlongAxis(2,FALSE,0); // njp1 = N_J+1; nkp1 = N_K+1; nion_i = NION_I; nion_j = NION_J; FloatARRAY II_VAR(njp1,nkp1,noGuard); II_VAR.setBase(1); FloatARRAY I_VAR(nion_i, nion_j,noGuard); I_VAR.setBase(1); Range ION_I(1,nion_i); Range ION_J(1,nion_j); Range Jp1(1,njp1); Range Kp1(1,nkp1); Range K2P3(1,N_K/2+3); istatus=ION2D_TAKE_VAR("x2ion\0",I_VAR.getDataPointer(),&nion_i,&nion_j,iStep,Time); ion->X2ion(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("y2ion\0",I_VAR.getDataPointer(),&nion_i,&nion_j,iStep,Time); ion->Y2ion(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("x_interp\0",I_VAR.getDataPointer(),&nion_i,&nion_j,iStep,Time); ion->X_interp(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("y_interp\0",I_VAR.getDataPointer(),&nion_i,&nion_j,iStep,Time); ion->Y_interp(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("rho0\0",II_VAR.getDataPointer(),&njp1,&nkp1,iStep,Time); ion->C0(Jp1,Kp1) = II_VAR(Jp1,Kp1); istatus=ION2D_TAKE_VAR("c0\0",II_VAR.getDataPointer(),&njp1,&nkp1,iStep,Time); ion->C0(Jp1,Kp1) = II_VAR(Jp1,Kp1); istatus=ION2D_TAKE_VAR("curnorth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->J1_interp_N(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("potnorth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Phi_N(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("SigmaH_north\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Sigma_H_N(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("SigmaP_north\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Sigma_P_N(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("fluxnorth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Flux_N(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("avE_north",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Av_Energy_N(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("cursouth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->J1_interp_S(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("potsouth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Phi_S(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("SigmaH_south\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Sigma_H_S(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("SigmaP_south\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Sigma_P_S(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("fluxsouth\0",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Flux_S(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus=ION2D_TAKE_VAR("avE_south",I_VAR.getDataPointer(),&nion_i, &nion_j,iStep,Time); ion->Av_Energy_S(ION_I,ION_J) = I_VAR(ION_I,ION_J); istatus = IONTAKE_CLOSE(); return true; } /***********************************************************************/ /// Close access to the HDF file. /** * @fixme Parse HDF 'istatus' variable so this function doesn't ALWAYS return true */ bool IonIO::close_hdf(void) { #ifdef DEBUG_MODE_ON printf("DEBUG: in IonIO.C::close_hdf(...)\n"); #endif int istatus; istatus = IONDUMP_CLOSE(); return true; }