Makefile for read and then write

# Start of the Makefile
# Defining Variables
# Syntax
# Target: Dependencies
# Command
#——————– specify netcdf library path ———————
#——————– for IITM Aaditya HPC —————————-
NETCDFINC = -I/gpfs1/home/Libs/INTEL/NETCDF4/netcdf-4.2.1/include
NETCDFLIB = -L/gpfs1/home/Libs/INTEL/NETCDF4/netcdf-4.2.1/lib

#———————————————————————-

LDFLAGS= $(NETCDFINC) $(NETCDFLIB) -lnetcdf -lnetcdff -g -traceback
FC=ifort

FFLAGS=-O3 -fp-model precise -vec-report -g -traceback -mcmodel=large -heap-arrays

OBJS=interp_eqhgt.o readfromnc.o check.o write2nc.o

# Makefile

read:$(OBJS)
$(FC) $(OBJS) $(LDFLAGS) -traceback -o exec

interp_eqhgt.o: interp_eqhgt.f90 readfromnc.o write2nc.o
$(FC) -c $(NETCDFINC) interp_eqhgt.f90
readfromnc.o: readfromnc.f90 check.o
$(FC) -c $(NETCDFINC) readfromnc.f90
write2nc.o: write2nc.f90
$(FC) -c $(NETCDFINC) write2nc.f90
check.o: check.f90
$(FC) -c $(NETCDFINC) check.f90
# —– This clean is executed only when you do “make clean” ———–
# —– If you do “make” then everything else above this “clean” ——-
# —– is executed —————————————————-

clean :
rm -rf $(OBJS)
rm -rf exec

# End of Makefile

Advertisements

Sample Makefile

ESM_HOME = /iitm2/cccr-res/prajeesh/iitm-esm-output_manager
EXEC = cfs_atmos_fcst
F77 = mpiifort
F90 = mpiifort
CC = mpicc

VPATH=../
FINCM = -I/iitm2/cccr-res/prajeesh/iitm-esm-parallel_coupling/src/lib/incmod/w3emc_v2.0.5_d

NETCDF = /gpfs1/home/Libs/INTEL/NETCDF4/netcdf-4.2.1

DEBUG1 = -gen-interfaces -warn interfaces
DEBUG2 = -check all -debug extended -check bounds
DEBUG3 = -warn declarations -fpe0
DEBUG4 = -warn unused -warn uncalled

DEBUG = -g -traceback

ARCH = -xAVX

OPTS = -O3 -fp-model precise -r8 -convert big_endian -align array32byte

FFLAG90 = $(OPTS) $(DEBUG) $(FINCM) -free
FFLAGS = $(OPTS) $(DEBUG) -fixed
FFLAGC = $(DEBUG) -fixed -O3 -fp-model precise -r8 -openmp -align array32byte
FFLAGSA = $(OPTS) $(DEBUG) $(FINCM) -fixed
FFLAGSF = $(DEBUG) -O3 -fp-model precise -convert big_endian -free -align array32byte # -vec-report6
FFLAGB = $(DEBUG) -O3 -fp-model precise -extend-source -convert big_endian -align array32byte # -vec-report6

LDR = mpiifort -mkl
LIBS = -L$(NETCDF)/lib -lnetcdf -lnetcdff -L/iitm2/cccr-res/prajeesh/iitm-esm-parallel_coupling/src/lib -lw3emc_v2.0.5_d -lw3nco_v2.0.5_d -lbacio_d

.SUFFIXES: .o .f .F .h
#
# *****************************************************************
#
OBJS0 = namelist_mod.o \
time_manager.o \
sfc_var_mod.o \
gfs_internalstate_mod.o \
gfs_initialize_mod.o \
gfs_run_mod.o \
gfs_standalone.o \
starttimeget.o \
set_local_lnt2_lonr_latr.o \
get_namgfs.o \
output_manager.o \
readfromnc.o \
check.o \
stringfunc.o \
spectralgridconv.o \
diag_tools.o \
data_override.o \
nc_io_mod.o \
time_interp.o \
land_model_mod.o \
error_mod.o \
interpred_mod.o \
ocean_mod.o \
albedo_mod.o \
surface_mod.o
OBJ_MOD = machine.o \
module.o \
iounitdef.o \
physcons_v.o \
funcphys_v.o \
progtm_module.o \
rascnvv2_v.o \
resol_def.o \
gg_def.o \
vert_def.o \
sig_io.o \
date_def.o \
layout1.o \
namelist_def.o \
namelist_soilveg.o \
coordinate_def.o \
tracer_const_h-new.o \
reduce_lons_grid_module.o \
matrix_sig_def.o \
mpi_def.o \
semi_lag_def.o \
deldifs_def.o \
bfilt_def.o \
sfcio_module.o \
sigio_module.o \
sigio_r_module.o \
gfsio_module.o \
gfsio_def.o \
module_bfmicrophysics.o
OBJS = \
get_cd_hyb.o get_am_bm_hyb.o\
get_cd_hyb_gc.o get_am_bm_hyb_gc.o\
setlats.o\
getysk.o\
getysk_gc.o\
redist_lats_a.o\
redist_lats_r_b_fix.o\
ifshuff.o\
shuffle_grid.o\
digifilt.o\
gcycle_v.o\
wrtout.o\
grid_collect.o\
info.o\
damp_speed.o\
deldifs.o\
fix_fields.o\
spect_fields.o\
delnpe.o\
delnpo.o \
dezouv.o\
impadj_sig.locl.o\
impadj_hyb.locl.o\
impadj_hyb.locl_gc.o\
dozeuv.o\
epslon.o\
filtr1eo.o \
filtr2eo.o\
get_ls_node.o\
get_lats_node_shuff_a_fix.o\
get_lats_node_shuff_r_fix.o\
getcon.o \
gfidi_sig.o\
gfidi_hyb.o\
gfidi_hyb_gc.o\
gfidi_hyb_gc_h-new.o\
glats.o\
gloopa_opt.o\
lon_lat_para.o\
compns.o\
gozrineo.o\
pln2eo.o \
rms_spect.o \
lats_shuff.o\
uvoedz.o \
mpi_quit.o \
sicdif_sig.o \
sicdif_hyb.o \
sicdif_hyb_gc.o \
dotstep_sicdif.o \
gather_times.o \
four2fln.o \
four2flnio.o \
sortrx.o \
sumfln.o \
sumder2.o \
triseori.o \
uveodz.o \
ysminv.o \
ver_sig.o \
four2grid_thread.o \
byteswap.o
OBJS_PORT = \
fftpack.o
#four2grid_thread.fftpack.o \

# noblas.o\
# funcphys_subsx.o\
#
OBJS_RAD = \
radlw_param.o \
radlw_datatb.o \
radlw_main.o \
radsw_param.o \
radsw_datatb.o \
radsw_main.o \
radiation_astronomy.o \
radiation_aerosols_KinneCMIP6.o \
radiation_gases.o \
radiation_clouds.o \
radiation_surface.o \
grrad.o \
gloopr.o

#

OBJS_PHY= \
ozinterp.o \
ozphys_v.o \
gloopb_call.gbphys.o\
gbphys_v.o \
gbphys_call.o \
gbphys_adv_hyb_gc.o \
gbphys_adv_hyb_gc_h-new.o \
dcyc2_v.o \
dcyc2_v.pre.rad.o \
set_soilveg.o \
sfc_land.o \
progt2_v.o \
sfc_diag.o \
sflx.o \
moninp_v.o \
moninp1_v.o \
moninq_v.o \
moninq1_v.o \
gwdps_v.o \
gwdc.o \
sascnv_v.o \
sascnvn_v.o \
cnvcld_v.o \
shalcv_v.o \
shalcv_v_opr.o \
shalcnv_v.o \
lrgsclr_v.o \
gscond_v.o \
precpd_v.o \
mstadb_v.o \
mstcnv_v.o \
get_prs_v.o \
gsmddrive_v.o \
omegtes.o \
omegtes_gc.o \
omegas.o \
hyb2sig.o \
hyb2press.o \
hyb2press_gc.o \
sig2press.o

###funcphys_subsx.o only srt gpxs was called in fix_fields -table not used

OBJS_IO= \
read_fix.o \
gribit.o \
wrtsfc.o \
para_fixio_w.o \
sfcsub.o \
treadeo.io.o \
treadeo.gfsio.o \
grid_to_spec.o \
spect_to_grid.o \
spect_tv_enthalpy_ps.o\
setsig.o \
twriteeo.o \
bafrio.o \
spect_send.o \
spect_write.o
OBJS_CC= \
mpi_more.o \
cmp.comm.o \
atm.comm.o \
tiles.o

SRC = $(OBJS0:.o=.f) $(OBJ_MOD:.o=.f) $(OBJS:.o=.f) $(OBJS_RAD:.o=.f) $(OBJS_PHY:.o=.f) $(OBJS_IO:.o=.f) $(OBJS_CC:.o=.f)
#
INCS = f_hpm.h mpi_inc.h function2

#
# *****************************************************************
#
all: model-mpi

model-mpi: $(OBJ_MOD) $(OBJS_CC) $(OBJS0) $(OBJS) $(OBJS_PHY) $(OBJS_RAD) $(OBJS_IO) $(OBJS_PORT)
$(LDR) $(LDFLAGS) -o $(EXEC) $(OBJ_MOD) $(OBJS_CC) $(OBJS0) $(OBJS) $(OBJS_PHY) $(OBJS_RAD) $(OBJS_IO) $(OBJS_PORT) $(LIBS)

clean:
rm -f $(OBJ_MOD) $(OBJS0) $(OBJS) $(OBJS_RAD) $(OBJS_PHY) $(OBJS_IO) *.mod *.o cfs_atmos_fcst

tar:
tar -cvf tar.gfs.r4r8 $(SRC) $(INCS) $(COMS) $(OBJS_PORT:.o=.f) lonsper* res* xx* Makefile* ini.* scr.* m*real_?

.F.o:
$(F77) $(FFLAGS) -c -d $<

%.o: %.f
$(F77) $(FFLAGS) -c $<

four2grid_thread.o: four2grid_thread.f fftpack.o
$(F77) $(FFLAGS) -c $<

fftpack.o: fftpack.f
$(F77) $(OPTS) -fixed -c $<

diag_tools.o: diag_tools.f90 spectralgridconv.o
$(F77) $(FFLAG90) -c $<

data_override.o: data_override.f90 nc_io_mod.o time_interp.o error_mod.o interpred_mod.o stringfunc.o
$(F77) $(FFLAG90) -c $<

land_model_mod.o: land_model_mod.f90 nc_io_mod.o error_mod.o interpred_mod.o ocean_mod.o
$(F77) $(FFLAG90) -I$(NETCDF)/include -c $<

ocean_mod.o: ocean_mod.f90
$(F77) $(FFLAG90) -c $<

nc_io_mod.o: nc_io_mod.f90 time_manager.o error_mod.o
$(F77) $(FFLAG90) -I$(NETCDF)/include -c $<

uvoedz.o: uvoedz.f layout1.o
$(F77) $(FFLAGS) -c $<

uveodz.o: uveodz.f layout1.o
$(F77) $(FFLAGS) -c $<

triseori.o: triseori.f layout1.o
$(F77) $(FFLAGS) -c $<

sumfln.o: sumfln.f layout1.o
$(F77) $(FFLAGS) -c $<

sumder2.o: sumder2.f layout1.o
$(F77) $(FFLAGS) -c $<

sicdif_hyb_gc.o: sicdif_hyb_gc.f layout1.o
$(F77) $(FFLAGS) -c $<

sicdif_hyb.o: sicdif_hyb.f layout1.o
$(F77) $(FFLAGS) -c $<

sicdif_sig.o: sicdif_sig.f layout1.o
$(F77) $(FFLAGS) -c $<

shuffle_grid.o: shuffle_grid.f layout1.o
$(F77) $(FFLAGS) -c $<

setlats.o: setlats.f layout1.o
$(F77) $(FFLAGS) -c $<

rms_spect.o: rms_spect.f layout1.o
$(F77) $(FFLAGS) -c $<

redist_lats_r_b_fix.o: redist_lats_r_b_fix.f layout1.o
$(F77) $(FFLAGS) -c $<

redist_lats_a.o: redist_lats_a.f layout1.o
$(F77) $(FFLAGS) -c $<

pln2eo.o: pln2eo.f layout1.o
$(F77) $(FFLAGS) -c $<

lon_lat_para.o: lon_lat_para.f layout1.o
$(F77) $(FFLAGS) -c $<

lats_shuff.o: lats_shuff.f layout1.o
$(F77) $(FFLAGS) -c $<

info.o: info.f layout1.o
$(F77) $(FFLAGS) -c $<

impadj_hyb.locl.o: impadj_hyb.locl.f layout1.o
$(F77) $(FFLAGS) -c $<

impadj_hyb.locl_gc.o: impadj_hyb.locl_gc.f layout1.o
$(F77) $(FFLAGS) -c $<

impadj_sig.locl.o: impadj_sig.locl.f layout1.o
$(F77) $(FFLAGS) -c $<

grid_collect.o: grid_collect.f layout1.o
$(F77) $(FFLAGS) -c $<

gozrineo.o: gozrineo.f layout1.o
$(F77) $(FFLAGS) -c $<

get_ls_node.o: get_ls_node.f layout1.o
$(F77) $(FFLAGS) -c $<

get_lats_node_shuff_r_fix.o: get_lats_node_shuff_r_fix.f layout1.o
$(F77) $(FFLAGS) -c $<

get_lats_node_shuff_a_fix.o: get_lats_node_shuff_a_fix.f layout1.o
$(F77) $(FFLAGS) -c $<

gather_times.o: gather_times.f layout1.o
$(F77) $(FFLAGS) -c $<

four2flnio.o: four2flnio.f layout1.o
$(F77) $(FFLAGS) -c $<

four2fln.o: four2fln.f layout1.o
$(F77) $(FFLAGS) -c $<

fix_fields.o: fix_fields.f layout1.o
$(F77) $(FFLAGS) -c $<

filtr2eo.o: filtr2eo.f layout1.o
$(F77) $(FFLAGS) -c $<

filtr1eo.o: filtr1eo.f layout1.o
$(F77) $(FFLAGS) -c $<

epslon.o: epslon.f layout1.o
$(F77) $(FFLAGS) -c $<

dozeuv.o: dozeuv.f layout1.o
$(F77) $(FFLAGS) -c $<

dezouv.o: dezouv.f layout1.o
$(F77) $(FFLAGS) -c $<

delnpo.o: delnpo.f layout1.o
$(F77) $(FFLAGS) -c $<

delnpe.o: delnpe.f layout1.o
$(F77) $(FFLAGS) -c $<

deldifs.o: deldifs.f layout1.o
$(F77) $(FFLAGS) -c $<

damp_speed.o: damp_speed.f layout1.o
$(F77) $(FFLAGS) -c $<

spect_fields.o: spect_fields.f date_def.o layout1.o
$(F77) $(FFLAGS) -c $<

ifshuff.o: ifshuff.f date_def.o layout1.o
$(F77) $(FFLAGS) -c $<

getcon.o: getcon.f date_def.o layout1.o
$(F77) $(FFLAGS) -c $<

omegas.o: omegas.f
$(F77) $(FFLAGS) -c $<

#
# *****************************************************************
#
cnvcld_v.o: cnvcld_v.f
$(F77) $(FFLAGS) -c $<

dcyc2_v.o: dcyc2_v.f
$(F77) $(FFLAGS) -c $<

dcyc2_v.pre.rad.o: dcyc2_v.pre.rad.f
$(F77) $(FFLAGS) -c $<

digifilt.o: digifilt.f date_def.o layout1.o dotstep_sicdif.o
$(F77) $(FFLAGS) -c $<

funcphys_subsx.o: funcphys_subsx.f
$(F77) $(FFLAGS) -c $<

gbphys_adv_hyb_gc.o: gbphys_adv_hyb_gc.f
$(F77) $(FFLAGS) -c $<

gbphys_adv_hyb_gc_h-new.o: gbphys_adv_hyb_gc_h-new.f
$(F77) $(FFLAGS) -c $<

gbphys_call.o: gbphys_call.f gbphys_v.o date_def.o layout1.o
$(F77) $(FFLAG90) -c $<

gbphys_v.o: gbphys_v.f output_manager.o sascnv_v.o sascnvn_v.o precpd_v.o lrgsclr_v.o moninp_v.o moninq_v.o moninp1_v.o sfc_diag.o dcyc2_v.o surface_mod.o
$(F77) $(FFLAG90) -c $<

get_prs_v.o: get_prs_v.f
$(F77) $(FFLAGS) -c $<

gscond_v.o: gscond_v.f
$(F77) $(FFLAGS) -c $<

gsmddrive_v.o: gsmddrive_v.f module_bfmicrophysics.o
$(F77) $(FFLAGS) -c $<

module_bfmicrophysics.o: module_bfmicrophysics.f
$(F77) $(FFLAGS) -c $<

gwdps_v.o: gwdps_v.f
$(F77) $(FFLAGS) -c $<

gwdc.o: gwdc.f
$(F77) $(FFLAGS) -c $<

hyb2press_gc.o: hyb2press_gc.f
$(F77) $(FFLAGS) -c $<

hyb2press.o: hyb2press.f
$(F77) $(FFLAGS) -c $<

hyb2sig.o: hyb2sig.f
$(F77) $(FFLAGS) -c $<

lrgsclr_v.o: lrgsclr_v.f
$(F77) $(FFLAGS) -c $<

moninp_v.o: moninp_v.f
$(F77) $(FFLAGS) -c $<

moninp1_v.o: moninp1_v.f
$(F77) $(FFLAGS) -c $<

moninq_v.o: moninq_v.f
$(F77) $(FFLAGS) -c $<

moninq1_v.o: moninq1_v.f
$(F77) $(FFLAGS) -c $<

mstadb_v.o: mstadb_v.f
$(F77) $(FFLAGS) -c $<

mstcnv_v.o: mstcnv_v.f
$(F77) $(FFLAGS) -c $<

omegtes_gc.o: omegtes_gc.f
$(F77) $(FFLAGS) -c $<

omegtes.o: omegtes.f
$(F77) $(FFLAGS) -c $<

ozinterp.o: ozinterp.f layout1.o
$(F77) $(FFLAGS) -c $<

ozphys_v.o: ozphys_v.f
$(F77) $(FFLAGS) -c $<

precpd_v.o: precpd_v.f
$(F77) $(FFLAGS) -c $<

rascnvv2_v.o: rascnvv2_v.f
$(F77) $(FFLAGS) -c $<

sfc_sice.o: sfc_sice.f
$(F77) $(FFLAGS) -c $<

set_soilveg.o: set_soilveg.f
$(F77) $(FFLAGS) -c $<

namelist_soilveg.o: namelist_soilveg.f
$(F77) $(FFLAGS) -c $<

sfc_land.o: sfc_land.f
$(F77) $(FFLAGS) -c $<

progt2_v.o: progt2_v.f
$(F77) $(FFLAGS) -c $<

sflx.o: sflx.f
$(F77) $(FFLAGS) -c $<

sfc_diag.o: sfc_diag.f
$(F77) $(FFLAGS) -c $<

sascnv_v.o: sascnv_v.f
$(F77) $(FFLAGS) -c $<

sascnvn_v.o: sascnvn_v.f
$(F77) $(FFLAGS) -c $<

shalcv_v.o: shalcv_v.f
$(F77) $(FFLAGS) -c $<

shalcv_v_opr.o: shalcv_v_opr.f
$(F77) $(FFLAGS) -c $<

shalcnv_v.o: shalcnv_v.f
$(F77) $(FFLAGS) -c $<

sig2press.o: sig2press.f
$(F77) $(FFLAGS) -c $<

# *****************************************************************

radlw_param.o: radlw_param.f
$(F77) $(FFLAGS) -c $<
radlw_datatb.o: radlw_datatb.f
$(F77) $(FFLAGS) -c $<
radlw_main.o: radlw_main.f radlw_datatb.o
$(F77) $(FFLAGSA) -c $<

radsw_param.o: radsw_param.f
$(F77) $(FFLAGS) -c $<

radsw_datatb.o: radsw_datatb.f
$(F77) $(FFLAGS) -c $<

radsw_main.o: radsw_main.f radsw_datatb.o
$(F77) $(FFLAGSA) -c $<

radiation_astronomy.o: radiation_astronomy.f
$(F77) $(FFLAGS) -c $<

radiation_aerosols_KinneCMIP6.o: radiation_aerosols_KinneCMIP6.f90 radsw_param.o radlw_param.o readfromnc.o
$(F77) $(FFLAGC) -c $<

radiation_gases.o: radiation_gases.f
$(F77) $(FFLAGS) -c $<

radiation_clouds.o: radiation_clouds.f
$(F77) $(FFLAGS) -c $<

radiation_surface.o: radiation_surface.f
$(F77) $(FFLAGS) -c $<

grrad.o: grrad.f radiation_astronomy.o radiation_aerosols_KinneCMIP6.o radiation_gases.o \
radiation_surface.o radiation_clouds.o radsw_main.o radsw_datatb.o \
radlw_main.o output_manager.o albedo_mod.o
$(F77) $(FFLAGS) -c $<

progtm_module.o: progtm_module.f
$(F77) $(FFLAGS) -c $<

machine.o: machine.f
$(F77) $(FFLAGS) -c $<

#
# *****************************************************************
#
physcons_v.o: physcons_v.f
$(F77) $(FFLAG90) -c $<

iounitdef.o: iounitdef.f
$(F77) $(FFLAG90) -c $<

funcphys_v.o: funcphys_v.f
$(F77) $(FFLAG90) -c $<

sfcio_module.o: sfcio_module.f
$(F77) $(FFLAGSF) -c $<

sigio_module.o: sigio_module.f
$(F77) $(FFLAGSF) -c $<

gfsio_def.o: gfsio_def.f
$(F77) $(FFLAGSF) -c $<

gfsio_module.o: gfsio_module.f
$(F77) $(FFLAGSF) -c $<

sigio_r_module.o: sigio_r_module.f
$(F77) $(FFLAGSF) -c $<

bafrio.o: bafrio.f
$(F77) $(FFLAGB) -c $<

read_fix.o: read_fix.f wrtout.o layout1.o sfcsub.o
$(F77) $(FFLAGS) -c $<

softcount.o: softcount.f
$(F77) $(FFLAGS) -c $<

gloopr.o: gloopr.f sumfln.o grrad.o date_def.o layout1.o diag_tools.o ocean_mod.o land_model_mod.o
$(F77) $(FFLAG90) -c $<

gloopb_call.gbphys.o: gloopb_call.gbphys.f gbphys_call.o sumfln.o output_manager.o date_def.o layout1.o
$(F77) $(FFLAG90) -c $<

sfcsub.o: sfcsub.f
$(F77) $(FFLAGS) -c $<

gcycle_v.o: gcycle_v.f layout1.o
$(F77) $(FFLAGS) -c $<

getaer.o: getaer.f
$(F77) $(FFLAGS) -c $<

gribit.o: gribit.f
$(F77) $(FFLAGS) -c $<

wrtsfc.o: wrtsfc.f layout1.o
$(F77) $(FFLAGS) -c $<

para_fixio_w.o: para_fixio_w.f layout1.o
$(F77) $(FFLAGS) -c $<

treadeo.io.o: treadeo.io.f layout1.o
$(F77) $(FFLAGS) -c $<

treadeo.gfsio.o: treadeo.gfsio.f layout1.o
$(F77) $(FFLAGS) -c $<

twriteeo.o: twriteeo.f layout1.o
$(F77) $(FFLAGS) -c $<

spect_send.o: spect_send.f layout1.o
$(F77) $(FFLAGS) -c $<

spect_write.o: spect_write.f layout1.o
$(F77) $(FFLAGS) -c $<

spect_to_grid.o: spect_to_grid.f date_def.o layout1.o
$(F77) $(FFLAGS) -c $<

spectralgridconv.o: spectralgridconv.f90 date_def.o layout1.o
$(F77) $(FFLAG90) -c $<

spect_tv_enthalpy_ps.o: spect_tv_enthalpy_ps.f sumfln.o date_def.o layout1.o
$(F77) $(FFLAGS) -c $<

grid_to_spec.o: grid_to_spec.f date_def.o layout1.o
$(F77) $(FFLAGS) -c $<

wrtout.o: wrtout.f layout1.o
$(F77) $(FFLAGS) -c $<

time_manager.o: time_manager.f90
$(F77) $(FFLAG90) -c $<

time_interp.o: time_interp.f90 time_manager.o
$(F77) $(FFLAG90) -c $<

namelist_mod.o: namelist_mod.f
$(F77) $(FFLAG90) -c $<

sfc_var_mod.o: sfc_var_mod.f
$(F77) $(FFLAG90) -c $<

gfs_internalstate_mod.o: gfs_internalstate_mod.f date_def.o layout1.o
$(F77) $(FFLAG90) -c $<

GFS_ErrMsgMod.o: GFS_ErrMsgMod.f
$(F77) $(FFLAG90) -c $<

gfs_initialize_mod.o: gfs_initialize_mod.f output_manager.o diag_tools.o data_override.o interpred_mod.o ocean_mod.o albedo_mod.o radiation_gases.o
$(F77) $(FFLAG90) -c $<

gfs_run_mod.o: gfs_run_mod.f date_def.o layout1.o dotstep_sicdif.o output_manager.o digifilt.o
$(F77) $(FFLAG90) -c $<

gfs_standalone.o: gfs_standalone.f gfs_run_mod.o gfs_initialize_mod.o
$(F77) $(FFLAG90) -c $<

starttimeget.o: starttimeget.f date_def.o
$(F77) $(FFLAG90) -c $<

mpi_more.o: mpi_more.f
$(F77) $(FFLAGS) -c $<

cmp.comm.o: cmp.comm.f
$(F77) $(FFLAGS) -c $<

atm.comm.o: atm.comm.f layout1.o land_model_mod.o ocean_mod.o
$(F77) $(FFLAGS) -c $<

tiles.o: tiles.f atm.comm.o
$(F77) $(FFLAGS) -c $<

dotstep_sicdif.o: dotstep_sicdif.f gloopa_opt.o gloopr.o gloopb_call.gbphys.o output_manager.o land_model_mod.o atm.comm.o wrtout.o
$(F77) $(FFLAG90) -c $<

set_local_lnt2_lonr_latr.o: set_local_lnt2_lonr_latr.f gfs_internalstate_mod.o
$(F77) $(FFLAG90) -c $<

get_namgfs.o: get_namgfs.f gfs_internalstate_mod.o
$(F77) $(FFLAG90) -c $<

output_manager.o: output_manager.f90 time_manager.o stringfunc.o error_mod.o tiles.o
$(F77) $(FFLAG90) -I$(NETCDF)/include -c $<

stringfunc.o: stringfunc.f90
$(F77) $(FFLAG90) -c $<

gloopa_opt.o: gloopa_opt.f sumfln.o date_def.o layout1.o
$(F77) $(FFLAGS) -c $<

error_mod.o: error_mod.f90 layout1.o mpi_def.o
$(F77) $(FFLAG90) -c $<

interpred_mod.o: interpred_mod.f90 layout1.o
$(F77) $(FFLAG90) -c $<

albedo_mod.o: albedo_mod.f90
$(F77) $(FFLAG90) -c $<

surface_mod.o: surface_mod.f90
$(F77) $(FFLAG90) -c $<
readfromnc.o: readfromnc.f90 check.o
$(F77) $(FFLAG90) -I$(NETCDF)/include -c $<
check.o: check.f90
$(F77) $(FFLAG90) -I$(NETCDF)/include -c $<
#get_topo.o: get_topo.f90
# $(F77) $(FFLAG90) -c $<

Read from netcdf file fortran 90 3 dimensional 3 variables

subroutine d3readfromnc(FILE_NAME,var1,var2,var3,outvar1,outvar2,outvar3,NLONS,NLATS,NRECS,lons,lats,time)

use netcdf
implicit none
! This is the name of the data file we will read.
character (len = 100) :: FILE_NAME
integer :: ncid,status,j
! We are reading 4D data, a 2 x 6 x 12 lvl-lat-lon grid, with 2
! timesteps of data.
integer,parameter :: NDIMS = 3
integer,parameter:: NLVLS = 1
character(len = 10),parameter :: LAY_NAME = “nb_sw”
character(len = 10),parameter :: LAT_NAME = “lat”
character(len = 10),parameter :: LON_NAME = “lon”
character(len = 10),parameter:: REC_NAME = “time”
integer :: lvl_dimid, lon_dimid, lat_dimid, rec_dimid,NRECS,NLONS,NLATS

! The start and count arrays will tell the netCDF library where to
! read our data.
integer :: start(NDIMS), count(NDIMS)

! In addition to the latitude and longitude dimensions, we will also
! create latitude and longitude variables which will hold the actual
! latitudes and longitudes. Since they hold data about the
! coordinate system, the netCDF term for these is: “coordinate
! variables.”
real :: lats(NLATS), lons(NLONS), time(NRECS)
integer :: lon_varid, lat_varid, time_varid

! We will read surface temperature and pressure fields. In netCDF
! terminology these are called “variables.”
character (len = 10) :: var1,var2,var3
integer :: var1id, var2id,var3id
integer :: dimids(NDIMS)
! Program variables to hold the data we will read in. We will only
! need enough space to hold one timestep of data; one record.
real,dimension(NLONS,NLATS,NRECS) :: outvar1,outvar2,outvar3
real,dimension(NLONS,NLATS,NRECS)::outdump1,outdump2,outdump3
!real,dimension(12,NLATS,NLONS) :: outvar1,outvar2,outvar3
! Loop indices
integer :: lvl, lat, lon, rec, i
!    print *,”***Opening nc File ***”, FILE_NAME, “!”
! Open the file.
status = nf90_open(FILE_NAME, nf90_nowrite, ncid)
!        print *,”*** ncid = “, ncid, “!”
! Get the varids of the latitude and longitude coordinate variables.
status = nf90_inq_varid(ncid, LAT_NAME, lat_varid)
status = nf90_inq_varid(ncid, LON_NAME, lon_varid)
status = nf90_inq_varid(ncid, REC_NAME, time_varid)
!        print *,”*** latid = “, lat_varid, “!”
!        print *,”*** lonid “, lon_varid, “!”
! Read the latitude and longitude data.
!        print *,”*** READING THE LAT AND LON DATA *** ”
status = nf90_get_var(ncid, lat_varid, lats)
status = nf90_get_var(ncid, lon_varid, lons)
status = nf90_get_var(ncid, time_varid,time)
do lat =1,NLATS

!       print *,”*** lat  “, lat, ” = “, lats

end do

do lon =1,NLONS

!        print *,”***lon “, lon, ” = “, lons

end do
! Check to make sure we got what we expected.
!        do lat = 1, NLATS
!        if (lats(lat) /= START_LAT + (lat – 1) * 5.0) stop 2
!        end do
!        do lon = 1, NLONS
!        if (lons(lon) /= START_LON + (lon – 1) * 5.0) stop 2
!        end do

! Get the varids of the pressure and temperature netCDF variables.
status = nf90_inq_varid(ncid, var1, var1id)
status = nf90_inq_varid(ncid, var2, var2id)
status = nf90_inq_varid(ncid, var3, var3id)
!        print *,”*** variable id of pressure =  “, var1id, “!”
!        print *,”*** variable id of temperature =  “, var2id, “!”
!        print *,”*** variable id of temperature =  “, var3id, “!”
! Read 1 record of NLVLS*NLATS*NLONS values, starting at the beginning
! of the record (the (1, 1, 1, rec) element in the netCDF file).
count = (/NLONS, NLATS, 1/)
! count = (/ 12, NLONS, NLATS/)
start = (/ 1, 1, 1/)

! Read the surface pressure and temperature data from the file, one
! record at a time.
do rec = 1, NRECS
start(3) = rec
call check(nf90_get_var(ncid, var1id, outdump1,start=start,count=count))

do j=1,180
do i=1,360
outvar1(i,j,rec)=outdump1(i,j,rec)
end do
end do

call check( nf90_get_var(ncid, var2id, outdump2,start,count))
do j=1,180
do i=1,360
outvar2(i,j,rec)=outdump2(i,j,rec)
end do
end do

call check( nf90_get_var(ncid, var3id, outdump3,start,count))

do j=1,180
do i=1,360
outvar3(i,j,rec)=outdump3(i,j,rec)
end do
end do

end do
!     print *, “get var for var 1 executed”
!     status = nf90_get_var(ncid, var2id, outvar2,start,count)
!     print *,”get var for var 2 executed”
!     status = nf90_get_var(ncid, var3id, outvar3,start,count)
!     print *,”get var for var 3 executed”
i  = 0
do lat = 1, NLATS
do lon = 1, NLONS
!             print *,”*** pressure “,lat,” “,lon,” =  “,pres_in

!              if (pres_in(lon, lat) /= SAMPLE_PRESSURE + i) stop 2
!              if (temp_in(lon, lat) /= SAMPLE_TEMP + i) stop 2
!              i = i + 1
!           end do
end do
! next record
end do

! Close the file. This frees up any internal netCDF resources
! associated with the file.
status = nf90_close(ncid)

! If we got this far, everything worked as expected. Yipee!
!        print *,”*** SUCCESS reading example file “, FILE_NAME, “!”

end subroutine d3readfromnc

subroutine check(status)
use netcdf
integer, intent ( in) :: status
if(status /= nf90_noerr) then
!call handle_err(status)
!print *, trim(nf90_strerror(status))
stop “Stopped”
end if
end subroutine check

Read from netcdf file fortran 90 4 dimensional 3 variables

subroutine d4readfromnc(FILE_NAME,var1,var2,var3,outvar1,outvar2,outvar3,NLONS,NLATS,NLAY,NRECS,lons,lats,lay,time)

use netcdf
implicit none
! This is the name of the data file we will read.
character (len = 100) :: FILE_NAME
integer :: ncid,status,j,k
! We are reading 4D data, a 2 x 6 x 12 lvl-lat-lon grid, with 2
! timesteps of data.
integer,parameter :: NDIMS = 4
integer:: NLAY
character(len = 10),parameter :: LAY_NAME = “nb_sw”
character(len = 10),parameter :: LAT_NAME = “lat”
character(len = 10),parameter :: LON_NAME = “lon”
character(len = 10),parameter:: REC_NAME = “time”
integer :: lvl_dimid, lon_dimid, lat_dimid, rec_dimid,NRECS,NLONS,NLATS

! The start and count arrays will tell the netCDF library where to
! read our data.
integer :: start(NDIMS), count(NDIMS)

! In addition to the latitude and longitude dimensions, we will also
! create latitude and longitude variables which will hold the actual
! latitudes and longitudes. Since they hold data about the
! coordinate system, the netCDF term for these is: “coordinate
! variables.”
real :: lats(NLATS), lons(NLONS),lay(NLAY), time(NRECS)
integer :: lon_varid, lat_varid, lay_varid,time_varid

! We will read surface temperature and pressure fields. In netCDF
! terminology these are called “variables.”
character (len = 10) :: var1,var2,var3
integer :: var1id, var2id,var3id
integer :: dimids(NDIMS)
! Program variables to hold the data we will read in. We will only
! need enough space to hold one timestep of data; one record.
real,dimension(NLONS,NLATS,NLAY,NRECS) :: outvar1,outvar2,outvar3
real,dimension(NLONS,NLATS,NLAY)::outdump1,outdump2,outdump3
!real,dimension(12,NLATS,NLONS) :: outvar1,outvar2,outvar3
! Loop indices
integer :: lvl, lat, lon, rec, i
print *,”***Opening nc File ***”, FILE_NAME, “!”
! Open the file.
status = nf90_open(FILE_NAME, nf90_nowrite, ncid)
print *,”*** ncid = “, ncid, “!”
! Get the varids of the latitude and longitude coordinate variables.
status = nf90_inq_varid(ncid, LAT_NAME, lat_varid)
status = nf90_inq_varid(ncid, LON_NAME, lon_varid)
status = nf90_inq_varid(ncid, LAY_NAME, lay_varid)
status = nf90_inq_varid(ncid, REC_NAME, time_varid)
print *,”*** latid = “, lat_varid, “!”
print *,”*** lonid “, lon_varid, “!”
!! Read the latitude and longitude data.
!        print *,”*** READING THE LAT AND LON DATA *** ”
status = nf90_get_var(ncid, lat_varid, lats)
status = nf90_get_var(ncid, lon_varid, lons)
status = nf90_get_var(ncid, lay_varid, lay)
status = nf90_get_var(ncid, time_varid,time)
do lat =1,NLATS

!       print *,”*** lat  “, lat, ” = “, lats

end do

do lon =1,NLONS

!        print *,”***lon “, lon, ” = “, lons

end do
! Check to make sure we got what we expected.
!        do lat = 1, NLATS
!        if (lats(lat) /= START_LAT + (lat – 1) * 5.0) stop 2
!        end do
!        do lon = 1, NLONS
!        if (lons(lon) /= START_LON + (lon – 1) * 5.0) stop 2
!        end do

! Get the varids of the pressure and temperature netCDF variables.
status = nf90_inq_varid(ncid, var1, var1id)
status = nf90_inq_varid(ncid, var2, var2id)
status = nf90_inq_varid(ncid, var3, var3id)
print *,”*** variable id of pressure =  “, var1id, “!”
print *,”*** variable id of temperature =  “, var2id, “!”
print *,”*** variable id of temperature =  “, var3id, “!”
! Read 1 record of NLVLS*NLATS*NLONS values, starting at the beginning
! of the record (the (1, 1, 1, rec) element in the netCDF file).
count = (/NLONS, NLATS,NLAY,1  /)
! count = (/ 12, NLONS, NLATS/)
start = (/ 1, 1, 1, 1/)

! Read the surface pressure and temperature data from the file, one
! record at a time.
do rec =1, NRECS
start(4) = rec
call check(nf90_get_var(ncid, var1id, outdump1,start=start,count=count))

do k=1,NLAY
do j=1,NLATS
do i=1,NLONS
outvar1(i,j,k,rec)=outdump1(i,j,k)

end do
end do
end do
call check( nf90_get_var(ncid, var2id, outdump2,start,count))

do k=1,NLAY
do j=1,NLATS
do i=1,NLONS
outvar2(i,j,k,rec)=outdump2(i,j,k)
end do
end do
end do

call check( nf90_get_var(ncid, var3id, outdump3,start,count))

do k=1,NLAY
do j=1,NLATS
do i=1,NLONS
outvar3(i,j,k,rec)=outdump3(i,j,k)
end do
end do
end do

end do
!     print *, “get var for var 1 executed”
!     status = nf90_get_var(ncid, var2id, outvar2,start,count)
!     print *,”get var for var 2 executed”
!     status = nf90_get_var(ncid, var3id, outvar3,start,count)
!     print *,”get var for var 3 executed”
i  = 0
do lat = 1, NLATS
do lon = 1, NLONS
!             print *,”*** pressure “,lat,” “,lon,” =  “,pres_in

!              if (pres_in(lon, lat) /= SAMPLE_PRESSURE + i) stop 2
!              if (temp_in(lon, lat) /= SAMPLE_TEMP + i) stop 2
!              i = i + 1
!           end do
end do
! next record
end do

! Close the file. This frees up any internal netCDF resources
! associated with the file.
status = nf90_close(ncid)

! If we got this far, everything worked as expected. Yipee!
print *,”*** SUCCESS reading example file “, FILE_NAME, “!”

end subroutine d4readfromnc

subroutine check(status)
use netcdf
integer, intent ( in) :: status
if(status /= nf90_noerr) then
!call handle_err(status)
!print *, trim(nf90_strerror(status))
stop “Stopped”
end if
end subroutine check

Read from netcdf file fortran 90 4 dimensional variable 2 variables

subroutine d4readfromnc_2vr(FILE_NAME,var1,var2,outvar1,outvar2,NLONS,NLATS,NLAY,NRECS,lons,lats,lay,time,LON_NAME,LAT_NAME,LAY_NAME,REC_NAME)

use netcdf
implicit none
! This is the name of the data file we will read.
character (len = *) :: FILE_NAME
integer :: ncid,status,j,k
! We are reading 4D data, a 2 x 6 x 12 lvl-lat-lon grid, with 2
! timesteps of data.
integer,parameter :: NDIMS = 4
integer:: NLAY
character(len = *):: LAY_NAME
character(len = *):: LAT_NAME
character(len = *):: LON_NAME
character(len = *):: REC_NAME
integer :: lvl_dimid, lon_dimid, lat_dimid, rec_dimid,NRECS,NLONS,NLATS

! The start and count arrays will tell the netCDF library where to
! read our data.
integer :: start(NDIMS), count(NDIMS)

! In addition to the latitude and longitude dimensions, we will also
! create latitude and longitude variables which will hold the actual
! latitudes and longitudes. Since they hold data about the
! coordinate system, the netCDF term for these is: “coordinate
! variables.”
real :: lats(NLATS), lons(NLONS),lay(NLAY), time(NRECS)
integer :: lon_varid, lat_varid, lay_varid,time_varid

! We will read surface temperature and pressure fields. In netCDF
! terminology these are called “variables.”
character (len = 10) :: var1,var2
integer :: var1id, var2id
integer :: dimids(NDIMS)
! Program variables to hold the data we will read in. We will only
! need enough space to hold one timestep of data; one record.
real,dimension(NLONS,NLATS,NLAY,NRECS) :: outvar1,outvar2
real,dimension(NLONS,NLATS,NLAY)::outdump1,outdump2,outdump3
!real,dimension(12,NLATS,NLONS) :: outvar1,outvar2,outvar3
! Loop indices
integer :: lvl, lat, lon, rec, i
!    print *,”***Opening nc File ***”, FILE_NAME, “!”
! Open the file.
status = nf90_open(FILE_NAME, nf90_nowrite, ncid)
!        print *,”*** ncid = “, ncid, “!”
! Get the varids of the latitude and longitude coordinate variables.
status = nf90_inq_varid(ncid, LAT_NAME, lat_varid)
status = nf90_inq_varid(ncid, LON_NAME, lon_varid)
status = nf90_inq_varid(ncid, LAY_NAME, lay_varid)
status = nf90_inq_varid(ncid, REC_NAME, time_varid)
!        print *,”*** latid = “, lat_varid, “!”
!        print *,”*** lonid “, lon_varid, “!”
! Read the latitude and longitude data.
!        print *,”*** READING THE LAT AND LON DATA *** ”
status = nf90_get_var(ncid, lat_varid, lats)
status = nf90_get_var(ncid, lon_varid, lons)
status = nf90_get_var(ncid, lay_varid, lay)
status = nf90_get_var(ncid, time_varid,time)
do lat =1,NLATS

!       print *,”*** lat  “, lat, ” = “, lats

end do

do lon =1,NLONS

!        print *,”***lon “, lon, ” = “, lons

end do
! Check to make sure we got what we expected.
!        do lat = 1, NLATS
!        if (lats(lat) /= START_LAT + (lat – 1) * 5.0) stop 2
!        end do
!        do lon = 1, NLONS
!        if (lons(lon) /= START_LON + (lon – 1) * 5.0) stop 2
!        end do

! Get the varids of the pressure and temperature netCDF variables.
status = nf90_inq_varid(ncid, var1, var1id)
status = nf90_inq_varid(ncid, var2, var2id)
!        print *,”*** variable id of pressure =  “, var1id, “!”
!        print *,”*** variable id of temperature =  “, var2id, “!”
! Read 1 record of NLVLS*NLATS*NLONS values, starting at the beginning
! of the record (the (1, 1, 1, rec) element in the netCDF file).
count = (/NLONS, NLATS,NLAY,1  /)
! count = (/ 12, NLONS, NLATS/)
start = (/ 1, 1, 1, 1/)

! Read the surface pressure and temperature data from the file, one
! record at a time.
do rec =1, NRECS
start(4) = rec
call check(nf90_get_var(ncid, var1id, outdump1,start=start,count=count))

do k=1,NLAY
do j=1,NLATS
do i=1,NLONS
outvar1(i,j,k,rec)=outdump1(i,j,k)

end do
end do
end do
call check( nf90_get_var(ncid, var2id, outdump2,start,count))

do k=1,NLAY
do j=1,NLATS
do i=1,NLONS
outvar2(i,j,k,rec)=outdump2(i,j,k)
end do
end do
end do

end do
!     print *, “get var for var 1 executed”
!     status = nf90_get_var(ncid, var2id, outvar2,start,count)
!     print *,”get var for var 2 executed”
!     status = nf90_get_var(ncid, var3id, outvar3,start,count)
i  = 0
do lat = 1, NLATS
do lon = 1, NLONS
!             print *,”*** pressure “,lat,” “,lon,” =  “,pres_in

!              if (pres_in(lon, lat) /= SAMPLE_PRESSURE + i) stop 2
!              if (temp_in(lon, lat) /= SAMPLE_TEMP + i) stop 2
!              i = i + 1
!           end do
end do
! next record
end do

! Close the file. This frees up any internal netCDF resources
! associated with the file.
status = nf90_close(ncid)

! If we got this far, everything worked as expected. Yipee!
!        print *,”*** SUCCESS reading example file “, FILE_NAME, “!”

end subroutine d4readfromnc_2vr

subroutine check(status)
use netcdf
integer, intent ( in) :: status
if(status /= nf90_noerr) then
!call handle_err(status)
print *, trim(nf90_strerror(status))
stop “Stopped”
end if
end subroutine check

Algorithm for nanmean on MATLAB

function y = nanmean(x,dim)
% FORMAT: Y = NANMEAN(X,DIM)
% 
%    Average or mean value ignoring NaNs
%
%    This function enhances the functionality of NANMEAN as distributed in
%    the MATLAB Statistics Toolbox and is meant as a replacement (hence the
%    identical name).  
%
%    NANMEAN(X,DIM) calculates the mean along any dimension of the N-D
%    array X ignoring NaNs.  If DIM is omitted NANMEAN averages along the
%    first non-singleton dimension of X.
%
%    Similar replacements exist for NANSTD, NANMEDIAN, NANMIN, NANMAX, and
%    NANSUM which are all part of the NaN-suite.
%
%    See also MEAN
if isempty(x)
	y = NaN;
	return
end

if nargin < 2
	dim = min(find(size(x)~=1));
	if isempty(dim)
		dim = 1;
	end
end

% Replace NaNs with zeros.
nans = isnan(x);
x(isnan(x)) = 0; 

% denominator
count = size(x,dim) - sum(nans,dim);

% Protect against a  all NaNs in one dimension
i = find(count==0);
count(i) = ones(size(i));

y = sum(x,dim)./count;
y(i) = i + NaN;