exe falls over after 10 iterations....

HI, I'm not sure what is useful information to help solve this problem, so apologies in advance!
I'm working with code half in C, half in F, I've added a component in C, called from F... The code compiles, and it seems to work, but then after 9 iterations of the daily components, it just stops (the new code is a daily component, and there's supposed to be several 1000 iterations)
I'm very new to both languages, could this be something to do with additional memory being taken up by the new calculations? or do I need to sift through to see if it's getting a value it doesn't like at this point.....
Any pointers gratefully appreciated!
Perhaps the source would help so we could see what's going on?
Thanks- I'll post the component- the code has 200ish components, so its hard to pick out what else is relevant.....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* SWT.c Calculate updated textural parameters for soilwater submodel*/
	#include <stdio.h>
	#include <stdlib.h>
	#include <math.h>
	#include "soilwater.h"
	#include "n2o_model.h"

extern LAYERPAR_SPT layers; float bulkd; float edepth; 
	  	float somsc;float ompc; 

void SWT(int *swflag, int ilyr, double fcsa, double fcsi, double fccl,
                 double fcom, double fcbd, double fcwp, double fcin,
                 double wpsa, double wpsi, double wpcl, 
                 double wpom, double pbd, double wpwp, double wpbd, double wpin, 
				 float som1c2, float som2c2, float som3c, float adep[CENTMAXLYR],
				 int *nlayer, int *numlyrs,float *bulkd,
                 float *pH, float awilt[], float afiel[])
 {
      int   clyr;
      float adepmin[CENTMAXLYR], adepmax[CENTMAXLYR];
      float width;

      adepmin[0] = 0.0f;
      adepmax[0] = adep[0];

 
      *bulkd = 0.0f;
      *pH = 0.0f;
      *swflag = 2;


 for (clyr=1; clyr < *nlayer; clyr++) {
        adepmin[clyr] = adepmax[clyr-1];
        adepmax[clyr] = adepmin[clyr] + adep[clyr];}

	  /* values for swflag 2 */	
	fcsa=0.5018; fcsi=0.8548; fccl=0.8833; fcom=4.966E-03;  
	fcbd=-0.2423; fcwp=0.0; fcin=0.0; wpsa=-0.0059; wpsi=0.1142; wpcl=0.5766;  
	wpom=2.228E-03; wpbd=0.02671; wpwp=0.0; wpin=0.0;

    

      /* Check for incompatible soil profiles  */ 
      
    
      for (clyr=0; clyr<=*nlayer; clyr++) {
        awilt[clyr] = 0.0f;
        afiel[clyr] = 0.0f;
        if (clyr == 0) {
          width = 0.0f;
          for (ilyr=layers->ubnd[clyr]; ilyr<= layers->lbnd[clyr]; ilyr++) 
		  {
            *bulkd += layers->bulkd[ilyr] * layers->width[ilyr];
            *pH += layers->pH[ilyr] * layers->width[ilyr];
            width += layers->width[ilyr];
          }
        
          *bulkd /= width;
          printf("bulkd = %5.2f\n", *bulkd);
        }
        
	  }
}
for (ilyr=layers->ubnd[clyr]; ilyr<= layers->lbnd[clyr]; ilyr++)
{

 /*Calculate updated textural parameters*/


		layers->fieldc[ilyr] = fcsa * layers->sandfrac[ilyr] + fcsi *
	 			(1  - (layers->sandfrac[ilyr] + layers->clayfrac[ilyr]))+
                     fccl * layers->clayfrac[ilyr]  + fcom * ompc +
                     fcbd * layers->bulkd[ilyr] + fcwp * layers->wiltpt[ilyr]+
					 fcin ;

           layers->wiltpt[ilyr] = wpsa * layers->sandfrac[ilyr] + wpsi *
	 		(1- (layers->sandfrac[ilyr] + layers->clayfrac[ilyr])) +
                      wpcl * layers->clayfrac[ilyr]  + wpom *ompc +
                      wpbd * layers->bulkd[ilyr] + wpwp * layers->wiltpt[ilyr] +
                      wpin;  

			somsc = som1c2 + som2c2 + som3c; 
			layers->ompc[ilyr] = somsc * 1.724/(10000 * layers->bulkd[ilyr] 
					  * layers->dpthmx[ilyr]-layers->dpthmn[ilyr]) ;


 /* Convert volumetric soil water content to  */
        /* soil water content per layer (in cm H2O) */

        layers->swcfc[ilyr] = layers->fieldc[ilyr] * layers->width[ilyr];
        layers->swcwp[ilyr] = layers->wiltpt[ilyr] * layers->width[ilyr];
}
width = 0.0f;
        for (ilyr=layers->ubnd[clyr]; ilyr<= layers->lbnd[clyr];ilyr++) {
          awilt[clyr] += layers->c[ilyr] * layers->width[ilyr];
          afiel[clyr] += layers->a[ilyr] * layers->width[ilyr];
          width += layers->width[ilyr];
        }
        awilt[clyr] /= width;
        afiel[clyr] /= width;
        printf("awilt[%1d] = %8.6f\n", clyr, awilt[clyr]);
        printf("afiel[%1d] = %8.6f\n", clyr, afiel[clyr]);
 
}
/* export calculated values*/
 	 printf("     update for SWC");
      printf(" ph and bd updates later\n"); 
       for (ilyr=0; ilyr < layers->numlyrs; ilyr++) {
          printf("%6.4f\t%6.4f\t", 
				 layers->fieldc[ilyr],layers->wiltpt[ilyr]); 
          printf("%4.2f\t%4.2f\t", 
                 layers->swcfc[ilyr], layers->swcwp[ilyr]);
      
		}
closed account (zb0S216C)
Anything of use from the debugger?

Wazzak
apologies, I'm a total newb, and I'm not quite sure what you mean by that?
If compiler warnings are helpful, it complains about conversion from double to float for lines 74, 80,84
closed account (zb0S216C)
hyplobates wrote:
"apologies, I'm a total newb, and I'm not quite sure what you mean by that?"

A debugger[1] is a program that helps track-down bugs in your program. It gives information as to what the values are for all objects in a program.

Use your debugger and set breakpoints. These are points within a program where the debugger stops the program and re-checks the values of all objects within scope.

It's difficult to determine why your code fails because so much information is missing. Your best bet is the debugger. Almost every compiler suite has one.

References:
[1] http://en.wikipedia.org/wiki/Debugger
Topic archived. No new replies allowed.