monkeycode
Technical User
I'm editing a model written in C and fortran- I've worked out how to use fortran variables in C, but not the reverse- any advice on what I'm doing wrong, or links to info on how to do this greatly appreciated- I don't even know the basics, like should I be using pointers (it seems to fall over when I do...)
I've added the module below to the C code, and I want to read obdc with the fortran component which calls this
the fortran component calling this is quite long, but the relevant bits
Thanks!
I've added the module below to the C code, and I want to read obdc with the fortran component which calls this
C:
#include <stdio.h>
#include <stdlib.h>
#include "n2o_model.h"
#include "soilwater.h"
#include <math.h>
extern LAYERPAR_SPT layers;
void bd_till(float *bdc, float obdc)
{
int ilyr;
printf("till*");
/* calcualte organic matter for tillage calculation*/
obdc = (layers->orgfrac[0]*layers->width[0] +
layers->orgfrac[1]*layers->width[1] +
layers->orgfrac[2]*layers->width[2]) /
(layers->width[0] + layers->width[1] + layers->width[2]);
printf("obdc %8.6f\n", obdc);
for (ilyr=0; ilyr < layers->numlyrs; ilyr++) {
layers->bulkd[ilyr] = layers->bulkd[ilyr] + *bdc;
}
/* printf("bdc = %8.6f\n", *bdc);printf("layers->bulkd[%1d] = %8.6f\n", ilyr, layers->bulkd[ilyr]);
printf("layers->bulkd[%1d] = %8.6f\n", ilyr, layers->bulkd[ilyr]);
bdc= *cultbd[1] + *cultbd[2] * layers->clayfrac[1] + *cultbd[3] *
(1- (layers->clayfrac[1] + layers->sandfrac[1])) + *cultbd[4] * layers->sandfrac[1]
+ *cultbd[5] * layers->orgfrac[1]; printf("bd_till");
printf("cultbd[1] = %8.6f\n",cultbd[1]);
printf("layers->clayfrac[%1d] = %8.6f\n", ilyr, layers->clayfrac[1]);bulkden = bulkden * *bdc;
printf("bulkden = %8.6f\n",*bulkden);*/
return;
}
the fortran component calling this is quite long, but the relevant bits
Code:
c ... Fortran to C prototype
INTERFACE
SUBROUTINE bd_till(bdc, obdc)
!MS$ATTRIBUTES ALIAS:'_bd_till' :: bd_till
REAL bdc
REAL obdc
END SUBROUTINE bd_till
END INTERFACE
call bd_till(bdc, obdc)
print *, "obdc", obdc
Thanks!