Changeset 5530


Ignore:
Timestamp:
Jul 18, 2008, 2:04:20 PM (16 years ago)
Author:
ole
Message:

Nariman and Ole fixed 64 bit issue with urs_ext.c.
NumSrc? was declared as a long, but wasn't casted to int in a loop where the iterator i was an int.
Solution: NumSrc? now declared as an int.
32 bit compatibility yet to be verified.

File:
1 edited

Legend:

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

    r5529 r5530  
    5050    float *weights;
    5151    int dimensions[2];
    52     long numSrc;
    53     long verbose;
     52    int numSrc;
     53    int verbose;
    5454    int nsta0;
    5555    int nt;
     
    9999    }
    100100
    101     muxFileNameArray = (char**)malloc((int)numSrc*sizeof(char*));
     101    muxFileNameArray = (char**)malloc(numSrc*sizeof(char*));
    102102    if (muxFileNameArray == NULL)
    103103    {
    104104        printf("ERROR: Memory for muxFileNameArray could not be allocated.\n");
    105         exit(-1);
     105        return NULL;
    106106    }
    107107
    108108    //printf("Checkpoint 2 for urs2sts_ext.c\n");   
     109    //printf("numSrc = %d\n", numSrc);
    109110    for (i = 0; i < numSrc; i++)
    110111    {
    111        
     112
     113        //printf("check 2.1, i=%d\n", i);         
    112114        fname = PyList_GetItem(filenames, i);
    113         if (!PyString_Check(fname))
    114         {
     115        //printf("check 2.2\n");                 
     116        if (!fname)
     117        {
     118          //printf("error\n");         
    115119            PyErr_SetString(PyExc_ValueError, "filename not a string");
    116             return NULL;
    117         }       
    118        
     120            return NULL;
     121        }       
     122        //printf("check 2.3\n");         
     123        //printf("fname = %s\n", PyString_AsString(fname));
     124       
     125       
     126        //printf("check 2.4\n"); 
    119127        muxFileNameArray[i] = PyString_AsString(fname);
    120128        if (muxFileNameArray[i] == NULL)
     
    135143    //printf("Checkpoint 4 for urs2sts_ext.c\n");       
    136144    // Create array for weights which are passed to read_mux2
    137     weights = (float*) malloc((int)numSrc*sizeof(float));
    138     for (i = 0; i < (int)numSrc; i++)
     145    weights = (float*) malloc(numSrc*sizeof(float));
     146    for (i = 0; i < numSrc; i++)
    139147    {
    140148        weights[i] = (float)(*(double*)(pyweights->data + i*pyweights->strides[0]));
     
    143151    //printf("Checkpoint 5 for urs2sts_ext.c\n");           
    144152    // Read in mux2 data from file
    145     cdata = _read_mux2((int)numSrc, muxFileNameArray, weights, (double*)file_params->data, (int)verbose);
     153    cdata = _read_mux2(numSrc,
     154                       muxFileNameArray,
     155                       weights,
     156                       (double*)file_params->data,
     157                       verbose);
    146158
    147159    //printf("Checkpoint 6 for urs2sts_ext.c\n");               
     
    237249}
    238250
    239 float** _read_mux2(int numSrc, char **muxFileNameArray, float *weights, double *params, int verbose)
     251float** _read_mux2(int numSrc,
     252                   char **muxFileNameArray,
     253                   float *weights,
     254                   double *params,
     255                   int verbose)
    240256{
    241257    FILE *fp;
     
    284300
    285301    /* loop over remaining sources, check compatibility, and read them into
    286     *muxData */ 
    287         for (isrc = 0; isrc < numSrc; isrc++)
     302    *muxData */ 
     303        for (isrc = 0; isrc < numSrc; isrc++)
    288304    {
    289305        muxFileName = muxFileNameArray[isrc];
    290306
    291                 /* open the mux file */
     307                /* open the mux file */
    292308        if((fp = fopen(muxFileName, "r")) == NULL)
    293309        {
     
    298314        if (!isrc)
    299315        {
    300                         fread(&nsta0, sizeof(int), 1, fp);
    301                        
    302                         fros = (int*)malloc(nsta0*numSrc*sizeof(int));
    303                         lros = (int*)malloc(nsta0*numSrc*sizeof(int));
     316            fread(&nsta0, sizeof(int), 1, fp);
     317       
     318            fros = (int*)malloc(nsta0*numSrc*sizeof(int));
     319            lros = (int*)malloc(nsta0*numSrc*sizeof(int));
    304320     
    305                         mytgs0 = (struct tgsrwg*)malloc(nsta0*sizeof(struct tgsrwg));
    306                         mytgs = (struct tgsrwg*)malloc(nsta0*sizeof(struct tgsrwg));
    307 
    308                         fread(mytgs0, nsta0*sizeof(struct tgsrwg), 1, fp);
     321            mytgs0 = (struct tgsrwg*)malloc(nsta0*sizeof(struct tgsrwg));
     322            mytgs = (struct tgsrwg*)malloc(nsta0*sizeof(struct tgsrwg));
     323
     324            fread(mytgs0, nsta0*sizeof(struct tgsrwg), 1, fp);
    309325        }
    310326        else
Note: See TracChangeset for help on using the changeset viewer.