/Users/huttone/Devel/sedflux-new/sedflux/trunk/ew/plume/plumedist.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  * PlumeDist    Calculate distance along/from centerline to all 
00023  *                      other points in the PLUME array "dist"
00024  *
00025  *      Author:         M.D. Morehead
00026  *      Original:       May 1998
00027  *
00028  * dist         lx,ly,5         -       information relating to closest centerline pt.
00029  *              [:,:,0:1]       -       x,y indices of the closest centerline point
00030  *              [:,:,2:3]       m       distances along/from centerline
00031  *              [:,:,4]         m/s     Albertson velocity at the centerline point
00032  *
00033  */
00034 #include "plumeinput.h"
00035 #include "plumevars.h"
00036 #include <utils/utils.h>
00037 
00038 int plumedist( Plume_grid *grid , Plume_options *opt )
00039 {
00040    void itoa(int,char[]);
00041 #ifdef DBG
00042    FILE *fiddbg;                        // dbg file
00043    char fndbg[11], ss[3];
00044 #endif
00045    int ii, jj, kk, k1, k2, kin;
00046    double dst1, dst0, rdis;
00047    
00048    // Max distance within the grid, for initial test value
00049    dst0 = sqrt( sq((grid->ymax-grid->ymin)) + sq((grid->xmax-grid->xmin)) );
00050 
00051    if ( opt->fjrd || opt->strt ) // vo ~ 0
00052    {
00053 
00054       for ( ii=0 ; ii<grid->lx ; ii++ )
00055       {
00056          for( jj=0 ; jj<grid->ly ; jj++ )
00057          {
00058             grid->dist[ii][jj][0] = (double)ii;
00059             grid->dist[ii][jj][1] = (double)(grid->zy);
00060             grid->dist[ii][jj][2] = grid->xval[ii];
00061             grid->dist[ii][jj][3] = fabs(grid->yval[jj]);
00062             grid->dist[ii][jj][4] = grid->pcent[ii][3];
00063          }
00064       }
00065 
00066    }
00067    else
00068    {   
00069  
00070       for( ii=0 ; ii<grid->lx ; ii++ )
00071       {
00072          jj = 0;
00073 
00074 #ifdef DBG
00075          fprintf( stderr ,
00076                   "\r  PlumeDist  ii = %d, lx = %d, ly = %d    " ,
00077                   ii ,
00078                   grid->lx ,
00079                   grid->ly );
00080 #endif
00081          //--- 
00082          // Find the radial distance to each centerline pt
00083          //  and find the minimum (the closest point)
00084          //---
00085          dst1 = dst0;
00086          for ( kk=0 ; kk<grid->lc ; kk++ )
00087          {
00088             rdis = sqrt(   sq(grid->pcent[kk][0]-grid->xval[ii])
00089                          + sq(grid->pcent[kk][1]-grid->yval[jj]) );
00090             if ( rdis < dst1 )
00091             {
00092                dst1 = rdis;
00093                kin = kk;
00094             }
00095          }
00096          // assign the jj=0,ii=0 dist values
00097          grid->dist[ii][jj][0] = grid->pcent[kin][0]/grid->dx;  // x index, along shore
00098          grid->dist[ii][jj][1] = grid->pcent[kin][1]/grid->dy;  // y index, cross shore
00099          grid->dist[ii][jj][2] = grid->pcent[kin][2]; // along plume distance
00100          grid->dist[ii][jj][3] = dst1;                // cross plume distance
00101          grid->dist[ii][jj][4] = grid->pcent[kin][3]; // centerline velocity
00102 
00103          for ( jj=1 ; jj<grid->ly ; jj++ )
00104          {
00105             // find a range of pcent indices around the last point
00106             k1 = mx( kin-npts, 0 );
00107             k2 = mn( kin+npts+1, grid->lc);
00108             // loop through find the closest centerline point
00109             dst1 = dst0;
00110             for ( kk=k1 ; kk<k2 ; kk++ )
00111             {
00112                rdis = sqrt(   sq(grid->pcent[kk][0]-grid->xval[ii])
00113                             + sq(grid->pcent[kk][1]-grid->yval[jj]) );
00114                if ( rdis < dst1 )
00115                {
00116                   dst1 = rdis;
00117                   kin = kk;
00118                }
00119             }
00120 
00121 
00122          // assign the dist values
00123             grid->dist[ii][jj][0] = grid->pcent[kin][0]/grid->dx; // x index, along shore
00124             grid->dist[ii][jj][1] = grid->pcent[kin][1]/grid->dy; // y index, cross shore
00125             grid->dist[ii][jj][2] = grid->pcent[kin][2]; // along plume distance
00126             grid->dist[ii][jj][3] = dst1;                // cross plume distance
00127             grid->dist[ii][jj][4] = grid->pcent[kin][3]; // centerline velocity
00128          }
00129       }
00130 
00131 #ifdef DBG
00132       fprintf(stderr,"\n");
00133 #endif
00134    } // endif( fjrd || strt ), else(curved)
00135    
00136 #ifdef DBG
00137    for ( kk=0 ; kk<5 ; kk++ )
00138    {
00139       strcpy( fndbg, "pdst" );
00140       itoa( kk, ss );
00141       strcat( fndbg, ss );
00142       strcat( fndbg, ".dat" );
00143       fprintf( stderr,"    Writing dist[ii][jj][%d] to %s \n", kk, fndbg );
00144 
00145       fiddbg = fopen(fndbg,"w");
00146       for( ii=0; ii<grid->lx; ii++)
00147       {
00148          for( jj=0; jj<ly; jj++ )
00149          {
00150             fprintf(fiddbg,"%5e  ", grid->dist[ii][jj][kk]);
00151          }
00152          fprintf(fiddbg,"\n");
00153       }
00154       fclose(fiddbg);
00155    }
00156 #endif
00157    
00158    return 0;
00159      
00160 } // end of PlumeDist
00161    

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