Changeset 5542


Ignore:
Timestamp:
Jul 21, 2008, 3:37:04 PM (16 years ago)
Author:
ole
Message:

Suppressed muxdata warning and did some formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/urs_ext.c

    r5541 r5542  
    2525#define POFFSET 5 //Number of site_params
    2626
    27 void fillDataArray(int, int, int, int, int *, int *, float *, int *, int *, float *);
     27void fillDataArray(int, int, int, int, int *, int *, float *,
     28                   int *, int *, float *);
    2829long getNumData(const int *fros, const int *lros, const int nsta);
    2930char isdata(float);
     
    4344
    4445    NOTE:
    45     A Python int is equivalent to a C long (this becomes really important on 64 bit architectures)
     46    A Python int is equivalent to a C long
     47    (this becomes really important on 64 bit architectures)
     48   
    4649    A Python double corresponds to a C double
    4750    */
     
    5053    PyArrayObject *pyweights;
    5154    PyArrayObject *file_params;
    52     PyArrayObject *permutation;   
     55    PyArrayObject *permutation;  // Ordering of selected stations   
    5356    PyArrayObject *pydata;
    5457    PyObject *fname;
     
    103106    if(PyList_Size(filenames) != pyweights->dimensions[0])
    104107    {
    105         PyErr_SetString(PyExc_ValueError, "Must specify one weight for each filename");
     108        PyErr_SetString(PyExc_ValueError,
     109                        "Must specify one weight for each filename");
    106110        return NULL;
    107111    }
     
    110114    if (muxFileNameArray == NULL)
    111115    {
    112         PyErr_SetString(PyExc_ValueError, "ERROR: Memory for muxFileNameArray could not be allocated.");
     116        PyErr_SetString(PyExc_ValueError,
     117          "ERROR: Memory for muxFileNameArray could not be allocated.");
    113118        return NULL;
    114119    }
     
    128133        {
    129134            PyErr_SetString(PyExc_ValueError,
    130                             "ERROR: Memory for muxFileNameArray could not be allocated.\n");
     135              "ERROR: Memory for muxFileNameArray could not be allocated.\n");
    131136            return NULL;
    132137        }
     
    136141    {
    137142        PyErr_SetString(PyExc_ValueError,
    138                         "file_params must be one-dimensional and of type double");
     143              "file_params must be one-dimensional and of type double");
    139144        return NULL;
    140145    }
     
    145150    for (i = 0; i < numSrc; i++)
    146151    {
    147         weights[i] = (float)(*(double*)(pyweights->data + i*pyweights->strides[0]));
    148     }
    149    
     152        weights[i] = (float)(*(double*)
     153                     (pyweights->data + i*pyweights->strides[0]));
     154    }
     155   
     156    // Desired number of stations
    150157    number_of_selected_stations = (int) permutation->dimensions[0];
    151158
     
    155162                       weights,
    156163                       (double*)file_params->data,
    157                        &number_of_selected_stations, // Desired number of stations
    158                        (long*) permutation->data, // Ordering of selected stations
     164                       &number_of_selected_stations,
     165                       (long*) permutation->data,
    159166                       verbose);
    160167
     
    193200    {
    194201        printf("ERROR: Gauge data has incorrect start and finish times:\n");
    195         printf("   start_tstep = %d, max_number_of_steps = %d\n", start_tstep, nt);
    196         printf("   finish_tstep = %d, min_number_of_steps = %d\n", finish_tstep, 0);   
     202        printf("   start_tstep = %d, max_number_of_steps = %d\n",
     203                   start_tstep, nt);
     204        printf("   finish_tstep = %d, min_number_of_steps = %d\n",
     205                   finish_tstep, 0);   
     206                   
    197207        PyErr_SetString(PyExc_ValueError, "Incorrect start and finish times"); 
    198208        return NULL;
     
    201211    if (start_tstep >= finish_tstep)
    202212    {
    203         PyErr_SetString(PyExc_ValueError, "ERROR: Gauge data has non-postive_length");
     213        PyErr_SetString(PyExc_ValueError,
     214                        "ERROR: Gauge data has non-postive_length");
    204215        return NULL;
    205216    }
     
    212223    if(pydata == NULL)
    213224    {
    214         PyErr_SetString(PyExc_ValueError, "ERROR: Memory for pydata array could not be allocated.");
     225        PyErr_SetString(PyExc_ValueError,
     226              "ERROR: Memory for pydata array could not be allocated.");
    215227        return NULL;
    216228    }
     
    218230   
    219231    // Each gauge begins and ends recording at different times. When a gauge is
    220     // not recording but at least one other gauge is. Pad the non-recording gauge
    221     // array with zeros.
     232    // not recording but at least one other gauge is.
     233    // Pad the non-recording gauge array with zeros.
    222234    for (i = 0; i < number_of_selected_stations; i++)
    223235    {
     
    229241                if (it + 1 > (int)cdata[i][nt + 4])
    230242                {
    231                     // This gauge has stopped recording but others are still recording
    232                     *(double*)(pydata->data + i*pydata->strides[0] + time*pydata->strides[1]) = 0.0;
     243                    // This gauge has stopped recording but others are
     244                    // still recording
     245                    *(double*)(pydata->data + i*pydata->strides[0]
     246                                            + time*pydata->strides[1]) =
     247                                            0.0;
    233248                }
    234249                else
    235250                {
    236                     *(double*)(pydata->data + i*pydata->strides[0] + time*pydata->strides[1]) = cdata[i][it];
     251                    *(double*)(pydata->data + i*pydata->strides[0]
     252                                            + time*pydata->strides[1]) =
     253                                            cdata[i][it];
    237254                }
    238255                time++;
     
    242259        for (j = 0; j < POFFSET; j++)
    243260        {
    244             *(double*)(pydata->data + i*pydata->strides[0] + (num_ts + j)*pydata->strides[1]) = cdata[i][nt + j];
     261            *(double*)(pydata->data + i*pydata->strides[0]
     262                                    + (num_ts + j)*pydata->strides[1]) =
     263                                    cdata[i][nt + j];
    245264        }
    246265    }
     
    277296    int number_of_selected_stations;
    278297    char susMuxFileName;
    279     float *muxData;
     298    float *muxData=NULL; // Suppress warning
    280299    long numData;
    281300
     
    286305    long int offset;
    287306
    288     /* Allocate space for the names and the weights and pointers to the data*/   
     307    /* Allocate space for the names and the weights and pointers to the data*/
    289308
    290309    /* Check that the input files have mux2 extension*/
     
    293312    {
    294313        muxFileName = muxFileNameArray[isrc];
    295         if(!susMuxFileName && strcmp(muxFileName + strlen(muxFileName) - 4, "mux2") != 0)
     314        if(!susMuxFileName && strcmp(muxFileName + strlen(muxFileName) - 4,
     315                                     "mux2") != 0)
    296316        {
    297317            susMuxFileName = 1;
     
    396416
    397417    // Apply rule that an empty permutation file means 'take all stations'
    398     // We can change this later by passing in None instead of the empty permutation.
    399 
    400        
     418    // We could change this later by passing in None instead of the empty
     419    // permutation.
    401420    number_of_selected_stations = *number_of_stations; 
    402421    if (number_of_selected_stations == 0)
    403422    {
    404423        number_of_selected_stations = nsta0; 
    405         *number_of_stations = nsta0;     // Return possibly updated number of stations
     424       
     425        // Return possibly updated number of stations
     426        *number_of_stations = nsta0;     
    406427     
    407428        // Create the Identity permutation vector
     
    422443       
    423444   
    424     /* Make array(s) to hold demuxed data for stations given in the permutation file */
     445    // Make array(s) to hold demuxed data for stations given in the
     446    // permutation file
    425447    sts_data = (float**)malloc(number_of_selected_stations*sizeof(float*));
    426448    if (sts_data == NULL)
     
    431453
    432454    // For each selected station, allocate space for its data
    433     len_sts_data = mytgs0[0].nt + POFFSET; // Max length of each timeseries (I think)
     455    len_sts_data = mytgs0[0].nt + POFFSET; // Max length of each timeseries?
    434456    for (i = 0; i < number_of_selected_stations; i++)
    435457    {
     
    527549
    528550/* thomas */
    529 void fillDataArray(int ista, int nsta, int nt, int ig, int *nst, int *nft, float *data, int *istart_p, int *istop_p, float *muxData)
     551void fillDataArray(int ista, int nsta, int nt, int ig, int *nst,
     552                   int *nft, float *data, int *istart_p,
     553                   int *istop_p, float *muxData)
    530554{
    531555    int it, last_it, jsta;
     
    562586    if (ig == -1 || nst[ista] == -1) /* currently ig==-1 => nst[ista]==-1 */
    563587    {
    564         /* gauge never started recording, or was outside of all grids, fill array with 0 */
     588        /* gauge never started recording, or was outside of all grids,
     589        fill array with 0 */
    565590        for(it = 0; it < nt; it++)
    566591        {
     
    593618            }   
    594619            else
    595                 /* gauge has finished recording */                                           
     620                /* gauge has finished recording */
    596621            {
    597622                data[it] = NODATA;
     
    606631
    607632        if(last_it < nt - 1)
    608             /* the loop was exited early because the gauge had finished recording */
     633            /* the loop was exited early because the gauge had
     634            finished recording */
    609635            for(it = last_it+1; it < nt; it++)
    610636                data[it] = NODATA;
     
    638664        {
    639665            numData += *(lros + ista) - *(fros + ista) + 1;
    640             last_output_step = (last_output_step < *(lros+ista) ? *(lros+ista):last_output_step);
     666            last_output_step = (last_output_step < *(lros+ista) ?
     667                                *(lros+ista):last_output_step);
    641668        }   
    642669        numData += last_output_step*nsta; /* these are the t records */
Note: See TracChangeset for help on using the changeset viewer.