/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/plume/plumeout1.c

Go to the documentation of this file.
00001 //---
00002 //
00003 // This file is part of sedflux.
00004 //
00005 // sedflux is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // sedflux is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with sedflux; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //
00019 //---
00020 
00021 /*
00022  * PlumeOut1.c  Prints the data to the output files for Plume (standalone)
00023  *              using MATLAB Binary file format
00024  *
00025  *      A one multidimensional file is written for each of the major variables:
00026  *      (where fname = the user input file name)
00027  *
00028  * filename     internal variable       description
00029  * --------     -----------------       -----------
00030  * fname.deps   deps(lx,ly,ngrains)     deposit thickness for each grain size
00031  * fname.ncnc   ncnc(lx,ly,ngrains)     non-conservative surface concentrations
00032  * fname.ccnc   ccnc(lx,ly,ngrains)     conservative values of surface concentrations
00033  * fname.sln    sln(lx,ly)              salinity (or any conservative tracer)
00034  * fname.ualb   ualb(lx,ly)             magnitude of the albertson velocities
00035  *
00036  *      Each file contains a header followed by the xval and yval arrays
00037  *      followed by the data arrays.
00038  *
00039  *      The header contains (one line for each variable):
00040  *              lx
00041  *              ly
00042  *              ngrains
00043  *              river.d0
00044  *
00045  *      Followed by an arrays of:
00046  *              xval(1:lx)
00047  *              yval(1:ly)
00048  *
00049  *      Then data arrays of the form:
00050  *              ccnc(1,1,1)  ccnc(1,2,1)  ... ccnc(1,ly,1)
00051  *              ccnc(2,1,1)  ccnc(2,2,1)  ... ccnc(2,ly,1)
00052  *              ...
00053  *              ccnc(lx,1,1) ccnc(lx,2,1) ... ccnc(lx,ly,1)
00054  *
00055  *              ccnc(1,1,2) ...
00056  *              ...             ccnc(lx,ly,2)
00057  *
00058  *              ccnc(1,1,ngrain) ...
00059  *              ...             ccnc(lx,ly,ngrain)
00060  *
00061  *      Author:         M.D. Morehead
00062  *      Original:       May 1998
00063  *
00064  */
00065 #include "plumeinput.h"
00066 #include "plumevars.h"
00067 #include <stdio.h>
00068 #include <string.h>
00069 
00070 int plumeout1(char fname[] , Plume_enviro *env , Plume_grid *grid )
00071 {
00072    FILE *fiddata;
00073    char fndata[20];
00074    int  ii, jj, kk, nn, zz;
00075 
00076    zz = 0;
00077 
00078    // loop through once for each parameter
00079    for( kk=0; kk<5; kk++ )
00080    {
00081       /*
00082        *        Create the file name
00083        */
00084       strcpy( fndata, fname );
00085       if( kk == 0 )
00086          strcat( fndata, ".ccnc" );
00087       else if( kk == 1 )
00088          strcat( fndata, ".ncnc" );
00089       else if( kk == 2 )
00090          strcat( fndata, ".deps" );
00091       else if( kk == 3 )
00092          strcat( fndata, ".sln" );
00093       else
00094          strcat( fndata, ".ualb" );
00095       /*
00096        *        Open the output file
00097        */
00098       if( (fiddata = fopen(fndata,"w")) == NULL)
00099       {
00100          fprintf( stderr ,
00101                   "  PlumeOut1 ERROR: Unable to open the output file. \n");
00102          fprintf(stderr, "    fndata = %s \n", fndata);
00103          eh_exit(1);
00104       }
00105       /*
00106        *        Write the header, xval and yval arrays
00107        */
00108       fwrite(       &grid->lx, sizeof(int),   1, fiddata );
00109       fwrite(       &grid->ly, sizeof(int),   1, fiddata );
00110       if( kk == 0 || kk == 1 || kk == 2 )
00111          fwrite(  &env->n_grains, sizeof(int),   1, fiddata );
00112       else
00113          fwrite( &zz             , sizeof(int)   , 1 , fiddata );
00114       fwrite( &env->river->d0 , sizeof(double) , 1 , fiddata );
00115       /*
00116        *        Write out the xval and yval arrays
00117        */
00118       for( ii=0; ii<grid->lx; ii++ )
00119          fwrite( &grid->xval[ii], sizeof(double), 1, fiddata );
00120       for( jj=0; jj<grid->ly; jj++ )
00121          fwrite( &grid->yval[jj], sizeof(double), 1, fiddata );
00122       /*
00123        *        Write the data array
00124        */
00125       if( kk == 0  ) {
00126          for( nn=0; nn<env->n_grains; nn++ ) {
00127          for( ii=0; ii<grid->lx; ii++ ) {
00128             for( jj=0; jj<grid->ly; jj++ ) {
00129                fwrite( &grid->ccnc[ii][jj][nn], sizeof(double), 1, fiddata );
00130       }  }  }  }
00131       else if( kk == 1 ) {
00132          for( nn=0; nn<env->n_grains; nn++ ) {
00133          for( ii=0; ii<grid->lx; ii++ ) {
00134             for( jj=0; jj<grid->ly; jj++ ) {
00135                fwrite( &grid->ncnc[ii][jj][nn], sizeof(double), 1, fiddata );
00136       }  }  }  }
00137       else if( kk == 2 ) {
00138          for( nn=0; nn<env->n_grains; nn++ ) {
00139          for( ii=0; ii<grid->lx; ii++ ) {
00140             for( jj=0; jj<grid->ly; jj++ ) {
00141                fwrite( &grid->deps[ii][jj][nn], sizeof(double), 1, fiddata );
00142       }  }  }  }
00143       else if( kk == 3 ) {
00144          for( ii=0; ii<grid->lx; ii++ ) {
00145          for( jj=0; jj<grid->ly; jj++ ) {
00146             fwrite( &grid->sln[ii][jj], sizeof(double), 1, fiddata );
00147       }  }  }
00148       else {
00149          for( ii=0; ii<grid->lx; ii++ ) {
00150          for( jj=0; jj<grid->ly; jj++ ) {
00151             fwrite( &grid->ualb[ii][jj], sizeof(double), 1, fiddata );
00152       }  }  }
00153         /* */ 
00154       fclose(fiddata);
00155    } /* end for(kk) */
00156    return(0);
00157 } // end of PlumeOut1
00158    

Generated on Fri Jan 4 18:04:15 2008 for sedflux by  doxygen 1.5.2