#! /bin/csh -xf

cd /home/vaa2/prakti/tmp/
foreach file ( sn199????.dat )


	set ofile = $file:r

	impbin \
		dim_sizes='1024 2048' \
		dim_names='line sample' \
		var_names='orig_mcsst interp_mcsst flag_data' \
		var_units='- - -' \
		var_types='by by by' \
		var_badvals='255 255 255' \
		sort_by_var='yes' \
		header_size='0' \
		rel_offsets='8 8 8' \
		instantiate='n' \
	$file ${ofile}.tdf

	subset \
		include_vars=	\
		clip_dims=sample	\
		range_pairs='1 1024'	\
		instantiate='n' \
	$file.tdf ${ofile}_left.tdf

	subset \
		include_vars=	\
		clip_dims=sample	\
		range_pairs='1025 2048'	\
		instantiate='n' \
	${ofile}.tdf ${ofile}_right.tdf

	concatenate	\
		include_vars=	\
		along_dim=2	\
	${ofile}_right.tdf ${ofile}_left.tdf ${ofile}_shift.tdf


	editdim			\
		dimname=sample	\
		newname=	\
		varname=	\
		scale=		\
		offset=1	\
		coord=		\
	${ofile}_shift.tdf

	copyxfm master_file=Master ${ofile}_shift.tdf

	fastreg2 \
        	master_file='0.5deg_grid' \
        	master_var= \
        	include_vars= \
        	brute_force='yes' \
        	poly_size='100' \
        	interpolate='nn' \
        	off_protect='no' \
        	whole_input='yes' \
        	add_to_output='no' \
	${ofile}_shift.tdf ${ofile}_shift.tdf.fr

	mv ${ofile}_shift.tdf.fr ${ofile}.tdf

	editdim \
        	dimname='line' \
        	newname='latitude' \
        	varname='<same>' \
        	scale='<same>' \
       		offset='<same>' \
        	coord='<same>' \
	${ofile}.tdf

	editdim \
        	dimname='sample' \
        	newname='longitude' \
        	varname='<same>' \
        	scale='<same>' \
        	offset='<same>' \
        	coord='<same>' \
	${ofile}.tdf

/bin/rm -f ${ofile}_right.tdf ${ofile}_left.tdf ${ofile}_shift.tdf

	~vav/src/HDF/tdftohdf2 'include_vars= ' ${ofile}.tdf ${ofile}.hdf

end
