00001 #include "copyright.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include "defs.h"
00024 #include "athena.h"
00025 #include "prototypes.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034 void output_tab_1d(MeshS *pM, OutputS *pOut, int nl, int nd);
00035 void output_tab_2d(MeshS *pM, OutputS *pOut, int nl, int nd);
00036 void output_tab_3d(MeshS *pM, OutputS *pOut, int nl, int nd);
00037
00038
00039
00040
00041
00042
00043 void output_tab(MeshS *pM, OutputS *pOut)
00044 {
00045 int nl,nd;
00046
00047
00048
00049 for (nl=0; nl<(pM->NLevels); nl++){
00050 for (nd=0; nd<(pM->DomainsPerLevel[nl]); nd++){
00051 if (pM->Domain[nl][nd].Grid != NULL){
00052
00053
00054 if ((pOut->nlevel == -1 || pOut->nlevel == nl) &&
00055 (pOut->ndomain == -1 || pOut->ndomain == nd)){
00056
00057 if (pOut->ndim == 3) {
00058 output_tab_3d(pM,pOut,nl,nd);
00059 } else if (pOut->ndim == 2) {
00060 output_tab_2d(pM,pOut,nl,nd);
00061 } else if (pOut->ndim == 1) {
00062 output_tab_1d(pM,pOut,nl,nd);
00063 }
00064 }}
00065 }
00066 }
00067
00068 return;
00069 }
00070
00071
00072
00073
00074
00075 void output_tab_1d(MeshS *pM, OutputS *pOut, int nl, int nd)
00076 {
00077 GridS *pGrid=pM->Domain[nl][nd].Grid;
00078 int i,nx1;
00079 FILE *pFile;
00080 char fmt[80],*fname,*plev=NULL,*pdom=NULL;
00081 char levstr[8],domstr[8];
00082 Real *data=NULL;
00083 Real dmin, dmax, xworld;
00084
00085
00086 if(pOut->dat_fmt == NULL){
00087 sprintf(fmt," %%12.8e");
00088 }
00089 else{
00090 sprintf(fmt," %s",pOut->dat_fmt);
00091 }
00092
00093
00094 data = OutData1(pGrid,pOut,&nx1);
00095 if (data == NULL) return;
00096
00097 minmax1(data,nx1,&dmin,&dmax);
00098
00099
00100 if (nl>0) {
00101 plev = &levstr[0];
00102 sprintf(plev,"lev%d",nl);
00103 }
00104 if (nd>0) {
00105 pdom = &domstr[0];
00106 sprintf(pdom,"dom%d",nd);
00107 }
00108
00109 if((fname = ath_fname(plev,pM->outfilename,plev,pdom,num_digit,pOut->num,
00110 pOut->id,"tab")) == NULL){
00111 ath_error("[output_tab]: Error constructing filename\n");
00112 }
00113
00114
00115 pFile = fopen(fname,"w");
00116 if (pFile == NULL) {
00117 ath_error("[output_tab]: Unable to open tab file %s\n",fname);
00118 }
00119
00120
00121 for (i=0; i<nx1; i++) {
00122 xworld = (float)(i);
00123 fprintf(pFile,fmt,xworld);
00124 fprintf(pFile,fmt,data[i]);
00125 fprintf(pFile,"\n");
00126 }
00127
00128
00129 pOut->gmin = MIN(dmin,pOut->gmin);
00130 pOut->gmax = MAX(dmax,pOut->gmax);
00131
00132 fclose(pFile);
00133 free_1d_array(data);
00134 }
00135
00136
00137
00138
00139
00140 void output_tab_2d(MeshS *pM, OutputS *pOut, int nl, int nd)
00141 {
00142 GridS *pGrid=pM->Domain[nl][nd].Grid;
00143 int i,j,nx1,nx2;
00144 FILE *pFile;
00145 char fmt[80],*fname,*plev=NULL,*pdom=NULL;
00146 char levstr[8],domstr[8];
00147 Real **data=NULL;
00148 Real dmin, dmax, xworld, yworld;
00149
00150
00151 if(pOut->dat_fmt == NULL){
00152 sprintf(fmt," %%12.8e");
00153 }
00154 else{
00155 sprintf(fmt," %s",pOut->dat_fmt);
00156 }
00157
00158
00159 data = OutData2(pGrid,pOut,&nx1,&nx2);
00160 if (data == NULL) return;
00161
00162 minmax2(data,nx2,nx1,&dmin,&dmax);
00163
00164
00165 if (nl>0) {
00166 plev = &levstr[0];
00167 sprintf(plev,"lev%d",nl);
00168 }
00169 if (nd>0) {
00170 pdom = &domstr[0];
00171 sprintf(pdom,"dom%d",nd);
00172 }
00173
00174 if((fname = ath_fname(plev,pM->outfilename,plev,pdom,num_digit,pOut->num,
00175 pOut->id,"tab")) == NULL){
00176 ath_error("[output_tab]: Error constructing filename\n");
00177 }
00178
00179
00180 pFile = fopen(fname,"w");
00181 if (pFile == NULL) {
00182 ath_error("[output_tab]: Unable to open tab file %s\n",fname);
00183 }
00184
00185
00186 for (j=0; j<nx2; j++) {
00187 for (i=0; i<nx1; i++) {
00188 xworld = (float)(i);
00189 yworld = (float)(j);
00190 fprintf(pFile,fmt,xworld);
00191 fprintf(pFile,fmt,yworld);
00192 fprintf(pFile,fmt,data[j][i]);
00193 fprintf(pFile,"\n");
00194 }
00195 }
00196
00197
00198 if (pOut->num == 0) {
00199 pOut->gmin = dmin;
00200 pOut->gmax = dmax;
00201 } else {
00202 pOut->gmin = MIN(dmin,pOut->gmin);
00203 pOut->gmax = MAX(dmax,pOut->gmax);
00204 }
00205
00206 fclose(pFile);
00207 free_2d_array(data);
00208 }
00209
00210
00211
00212
00213
00214 void output_tab_3d(MeshS *pM, OutputS *pOut, int nl, int nd)
00215 {
00216 GridS *pGrid=pM->Domain[nl][nd].Grid;
00217 int i,j,k,nx1,nx2,nx3;
00218 FILE *pFile;
00219 char fmt[80],*fname,*plev=NULL,*pdom=NULL;
00220 char levstr[8],domstr[8];
00221 Real ***data, dmin, dmax, xworld, yworld, zworld;
00222
00223
00224 if(pOut->dat_fmt == NULL){
00225 sprintf(fmt," %%12.8e");
00226 }
00227 else{
00228 sprintf(fmt," %s",pOut->dat_fmt);
00229 }
00230
00231
00232 data = OutData3(pGrid,pOut,&nx1,&nx2,&nx3);
00233 minmax3(data,nx3,nx2,nx1,&dmin,&dmax);
00234
00235
00236 if (nl>0) {
00237 plev = &levstr[0];
00238 sprintf(plev,"lev%d",nl);
00239 }
00240 if (nd>0) {
00241 pdom = &domstr[0];
00242 sprintf(pdom,"dom%d",nd);
00243 }
00244
00245 if((fname = ath_fname(plev,pM->outfilename,plev,pdom,num_digit,pOut->num,
00246 pOut->id,"tab")) == NULL){
00247 ath_error("[output_tab]: Error constructing filename\n");
00248 }
00249
00250
00251 pFile = fopen(fname,"w");
00252 if (pFile == NULL) {
00253 ath_error("[output_tab]: Unable to open tab file %s\n",fname);
00254 }
00255
00256
00257 for (k=0; k<nx3; k++) {
00258 for (j=0; j<nx2; j++) {
00259 for (i=0; i<nx1; i++) {
00260 xworld = (float)(i);
00261 yworld = (float)(j);
00262 zworld = (float)(k);
00263 fprintf(pFile,fmt,xworld);
00264 fprintf(pFile,fmt,yworld);
00265 fprintf(pFile,fmt,zworld);
00266 fprintf(pFile,fmt,data[k][j][i]);
00267 fprintf(pFile,"\n");
00268 }
00269 }
00270 }
00271
00272
00273 if (pOut->num == 0) {
00274 pOut->gmin = dmin;
00275 pOut->gmax = dmax;
00276 } else {
00277 pOut->gmin = MIN(dmin,pOut->gmin);
00278 pOut->gmax = MAX(dmax,pOut->gmax);
00279 }
00280
00281 fclose(pFile);
00282 free_3d_array(data);
00283 }